diff --git a/CHANGELOG.md b/CHANGELOG.md index 88eb3031..1811dc12 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## 6.20.5 - Sept 18, 2024 + +* Improve Event to Person matching + ## 6.20.4 - Sept 16, 2024 * Add Chamber on Bill Sponsorship matches for people diff --git a/openstates/importers/base.py b/openstates/importers/base.py index cede0aa3..b50beca7 100644 --- a/openstates/importers/base.py +++ b/openstates/importers/base.py @@ -588,14 +588,20 @@ def resolve_person( memberships__start_date__lt=end_date ) - ids = set(Person.objects.filter(spec).values_list("id", flat=True)) - if len(ids) == 1: - self.person_cache[cache_key] = ids.pop() - errmsg = None - elif not ids: + query_result = Person.objects.filter(spec).values("id", "current_role") + result_set = set([p["id"] for p in query_result]) + errmsg = None + if len(result_set) == 1: + self.person_cache[cache_key] = result_set.pop() + elif not result_set: errmsg = "no people returned for spec" else: - errmsg = "multiple people returned for spec" + # If there are multiple rows returned see we can get the active legislator. + ids = set([p["id"] for p in query_result if p["current_role"] is not None]) + if len(ids) == 1: + self.person_cache[cache_key] = ids.pop() + else: + errmsg = "multiple people returned for spec" # either raise or log error if errmsg: diff --git a/pyproject.toml b/pyproject.toml index a71c26bc..2edf1fb8 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "openstates" -version = "6.20.4" +version = "6.20.5" description = "core infrastructure for the openstates project" authors = ["James Turk "] license = "MIT"