From 4410592beabba1cfca25ea2daaed79ea5423aa27 Mon Sep 17 00:00:00 2001 From: alexobaseki Date: Tue, 17 Sep 2024 17:46:18 -0400 Subject: [PATCH 1/3] Improve multiple people return resolve_person() --- openstates/importers/base.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/openstates/importers/base.py b/openstates/importers/base.py index cede0aa3..e4b65e9a 100644 --- a/openstates/importers/base.py +++ b/openstates/importers/base.py @@ -588,14 +588,19 @@ 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") + errmsg = None + if len(query_result) == 1: + self.person_cache[cache_key] = query_result[0]["id"] + elif not query_result: errmsg = "no people returned for spec" else: - errmsg = "multiple people returned for spec" + # If there are multiple rows returned see we can get the current + ids = set([entry["id"] for entry in query_result if entry["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: From bde7c3ffc2256f2e1be53fe7f7b66745c712fe07 Mon Sep 17 00:00:00 2001 From: alexobaseki Date: Tue, 17 Sep 2024 18:07:22 -0400 Subject: [PATCH 2/3] Ensure query result are a set --- openstates/importers/base.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/openstates/importers/base.py b/openstates/importers/base.py index e4b65e9a..b50beca7 100644 --- a/openstates/importers/base.py +++ b/openstates/importers/base.py @@ -589,14 +589,15 @@ def resolve_person( ) query_result = Person.objects.filter(spec).values("id", "current_role") + result_set = set([p["id"] for p in query_result]) errmsg = None - if len(query_result) == 1: - self.person_cache[cache_key] = query_result[0]["id"] - elif not query_result: + if len(result_set) == 1: + self.person_cache[cache_key] = result_set.pop() + elif not result_set: errmsg = "no people returned for spec" else: - # If there are multiple rows returned see we can get the current - ids = set([entry["id"] for entry in query_result if entry["current_role"] is not None]) + # 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: From 751838225fa4d32cce5719c8d4a4867d06f4e18b Mon Sep 17 00:00:00 2001 From: alexobaseki Date: Wed, 18 Sep 2024 10:46:03 -0400 Subject: [PATCH 3/3] Update version --- CHANGELOG.md | 4 ++++ pyproject.toml | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) 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/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"