Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve multiple people return resolve_person() #142

Merged
merged 3 commits into from
Sep 18, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions openstates/importers/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Loading