datamade / django-councilmatic

:heartpulse: Django app providing core functions for *.councilmatic.org
http://councilmatic.org
MIT License
26 stars 16 forks source link

RelatedObjectDoesNotExist: Bill has no councilmatic_bill. #257

Closed sentry-io[bot] closed 4 years ago

sentry-io[bot] commented 5 years ago

sometimes, when an existing ocd bill is saved, there is not an associated councilmatic bill. note that each of these exceptions is associated with an ocd bill that no longer exists.

this begs the question, how is the save method being called on a bill that doesn't exist?

one thing that does not answer the question, but would solve the immediate problem, is to remove this defensive else statement:

https://github.com/datamade/django-councilmatic/blob/0cde8a0d90835d9918154d832dd1e38cc4596324/councilmatic_core/signals/handlers.py#L64-L65

on the one hand, it's prudent. on the other, we don't do it in any of the other signals. i'd be more comfortable if we understood the deeper cause here, though.

Sentry Issue: SCRAPERS-US-MUNICIPAL-119

RelatedObjectDoesNotExist: Bill has no councilmatic_bill.
(9 additional frame(s) were not displayed)
...
  File "django/db/models/base.py", line 769, in save_base
    update_fields=update_fields, raw=raw, using=using,
  File "django/dispatch/dispatcher.py", line 178, in send
    for receiver in self._live_receivers(sender)
  File "django/dispatch/dispatcher.py", line 178, in <listcomp>
    for receiver in self._live_receivers(sender)
  File "councilmatic_core/signals/handlers.py", line 65, in create_councilmatic_bill
    cb = instance.councilmatic_bill
  File "django/db/models/fields/related_descriptors.py", line 389, in __get__
    self.related.get_accessor_name()

RelatedObjectDoesNotExist: Bill has no councilmatic_bill.
fgregg commented 4 years ago

This was fixed by https://github.com/datamade/scrapers-us-municipal/commit/7abbc4df57184437b68ade4bd9e2d8dcc7d66f3d

hancush commented 4 years ago

This recurred with the Metro dashboard. The staging database had a hundred some-odd OCD bills without a corresponding Councilmatic bill.

I believe this is because the dashboard scripts were missing the SHARED_DB flag – I added this a couple of days ago, and it was brought in yesterday: https://github.com/datamade/la-metro-dashboard/commit/eb372757fc777f9157b9813bfca482dbe1624616. Same issue we had with Chicago in https://github.com/datamade/django-councilmatic/issues/257#issuecomment-556907007.

I checked the production database and confirmed that there were no OCD bills without Councilmatic bills, i.e., this is not a deeper problem with pupa et al. To resolve the existing data issue, I manually added Councilmatic bills to the OCD bills in the Metro staging database that didn’t have them.