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

Events to Bills: Add -1 Day to Match Query #141

Merged
merged 7 commits into from
Sep 16, 2024
20 changes: 19 additions & 1 deletion openstates/importers/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import json
import logging
import typing
from datetime import datetime, timedelta
from django.db.models import Q, Model
from django.db.models.signals import post_save
from .. import settings
Expand Down Expand Up @@ -180,7 +181,24 @@ def resolve_bill(self, bill_id: str, *, date: str) -> typing.Optional[_ID]:
if len(ids) == 1:
return ids.pop()
elif len(ids) == 0:
NewAgeAirbender marked this conversation as resolved.
Show resolved Hide resolved
self.error(f"could not resolve bill id {bill_id} {date}, no matches")
self.warning(f"could not resolve bill id {bill_id} {date}, no matches so will retry")
date = datetime.fromisoformat(date)
new_date = date + timedelta(days=-4)
NewAgeAirbender marked this conversation as resolved.
Show resolved Hide resolved
objects = Bill.objects.filter(
Q(legislative_session__end_date__gte=new_date)
| Q(legislative_session__end_date=""),
legislative_session__start_date__lte=new_date,
legislative_session__jurisdiction_id=self.jurisdiction_id,
identifier=bill_id,
)
ids = {each.id for each in objects}
if len(ids) == 1:
self.info(f"resolved bill id {bill_id} with tweaked start_date {new_date}")
return ids.pop()
else:
self.error(
f"could not resolve bill with tweaked date {bill_id} {new_date}, {len(ids)} matches"
)
else:
self.error(
f"could not resolve bill id {bill_id} {date}, {len(ids)} matches"
Expand Down
Loading