From c8ed94352b987ec3109121b68a27ea37f573b09c Mon Sep 17 00:00:00 2001 From: Jesse Mortenson Date: Thu, 10 Oct 2024 17:15:50 -0500 Subject: [PATCH 1/3] Fix organization chamber match when bill sponsor is organization --- openstates/importers/organizations.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/openstates/importers/organizations.py b/openstates/importers/organizations.py index ceb77c10..44a3de6e 100644 --- a/openstates/importers/organizations.py +++ b/openstates/importers/organizations.py @@ -15,6 +15,9 @@ 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 @@ -23,8 +26,14 @@ def limit_spec(self, spec: _JsonDict) -> _JsonDict: 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 From c4bc33562516552148231b60d97166bab7e77e9a Mon Sep 17 00:00:00 2001 From: Jesse Mortenson Date: Thu, 10 Oct 2024 17:44:17 -0500 Subject: [PATCH 2/3] Add release details --- CHANGELOG.md | 4 ++++ pyproject.toml | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) 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/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" From 05ed5f216b731f9ca150ec322d96c1ad59e26085 Mon Sep 17 00:00:00 2001 From: Jesse Mortenson Date: Thu, 10 Oct 2024 17:48:32 -0500 Subject: [PATCH 3/3] Black reformatting --- openstates/importers/organizations.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/openstates/importers/organizations.py b/openstates/importers/organizations.py index 44a3de6e..a8e1961e 100644 --- a/openstates/importers/organizations.py +++ b/openstates/importers/organizations.py @@ -22,18 +22,20 @@ def limit_spec(self, spec: _JsonDict) -> _JsonDict: # __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 ") if chamber_classification: - return Q(**spec) & ( - Q(name__iexact=name) - | Q(other_names__contains=[{"name": name}]) - ) & Q(parent__classification=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}]) + Q(name__iexact=name) | Q(other_names__contains=[{"name": name}]) ) return spec