diff --git a/CHANGELOG.md b/CHANGELOG.md index b926e682..65094c9a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## 6.20.7 - Oct 10, 2024 + +* Fix matching committee organizations when chamber is specified for an organizational bill sponsor + ## 6.20.6 - Sept 18, 2024 * Add steps to publish lightweight openstates-metadata diff --git a/openstates/importers/organizations.py b/openstates/importers/organizations.py index ceb77c10..a8e1961e 100644 --- a/openstates/importers/organizations.py +++ b/openstates/importers/organizations.py @@ -15,16 +15,27 @@ def limit_spec(self, spec: _JsonDict) -> _JsonDict: org_name_prepositions = ["and", "at", "by", "for", "in", "on", "of", "the"] name = spec.pop("name", None) + # if chamber is included in pseudo_person_id, we assume this is a committee + # and chamber is here to help us find its parent + chamber_classification = spec.pop("chamber", None) if name: # __icontains doesn't work for JSONField ArrayField # so name follows "title" naming pattern name = name.title() - pattern = '(' + '|'.join(org_name_prepositions) + ')' - name = re.sub(pattern, lambda match: match.group(0).lower(), name, flags=re.IGNORECASE) + pattern = "(" + "|".join(org_name_prepositions) + ")" + name = re.sub( + pattern, lambda match: match.group(0).lower(), name, flags=re.IGNORECASE + ) name = name.replace(" & ", " and ") - return Q(**spec) & ( - Q(name__iexact=name) - | Q(other_names__contains=[{"name": name}]) - ) + if chamber_classification: + return ( + Q(**spec) + & (Q(name__iexact=name) | Q(other_names__contains=[{"name": name}])) + & Q(parent__classification=chamber_classification) + ) + else: + return Q(**spec) & ( + Q(name__iexact=name) | Q(other_names__contains=[{"name": name}]) + ) return spec diff --git a/pyproject.toml b/pyproject.toml index 7202e7af..d2419e80 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "openstates" -version = "6.20.6" +version = "6.20.7" description = "core infrastructure for the openstates project" authors = ["James Turk "] license = "MIT"