-
Notifications
You must be signed in to change notification settings - Fork 0
Conversation
hm, @jeancochrane, i'm getting test failures, even after installing django-councilmatic as instructed:
|
@hancush Did you switch to the new branch ( |
hhhhhmmmmmmmmmmmmm @ myself. thanks, @jeancochrane, you're right. sorry about that. |
@hancush Since |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is great, @jeancochrane. thank you so much for this thoughtful refactor. left a few commends/questions inline.
from django.contrib.postgres.fields import JSONField | ||
try: | ||
HAYSTACK_URL = settings.HAYSTACK_CONNECTIONS['default']['URL'] | ||
except KeyError: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is totally up to your judgment: do you think we should log a warning that solr is not configured if the app starts without this setting, either in addition to or instead of logging when the management command is sent?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like that idea a lot, but do you have any sense of how we'd hook into the app start event to emit the warning? Not sure when that happens and I can't find anything from a cursory search.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think that this will get evaluated when you start the app, no extra steps required. (added a print statement to the except block to test.)
(chi-councilmatic) call-me-hank:chi-councilmatic hannah$ python manage.py runserver
no haystack url
that said, as i was testing that assumption, i learned haystack itself will raise a fatal exception if you don't define the default connection, so maybe we don't need to do anything ourselves.
raise ImproperlyConfigured("The default alias '%s' must be included in the HAYSTACK_CONNECTIONS setting." % DEFAULT_ALIAS)
django.core.exceptions.ImproperlyConfigured: The default alias 'default' must be included in the HAYSTACK_CONNECTIONS setting.
what do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! I think the built-in error is definitely more informative than ours anyway. The only open question to me is whether or not there's a use-case for running this app without search support. If so, it might make more sense to handle the error gently with a warning rather than raise a fatal error IMO. But if we imagine that wiring up Haystack is a necessary prerequisite for the app, then I think we can safely get rid of our error and rely on Haystack to complain.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
haystack is a pre-req of django-councilmatic, so if we can't envision running notifications without django-councilmatic, then i think haystack is a necessary pre-req here. does that logic check out?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense to me 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think we we landed on the app not being able to run without search, i.e., we can rely on haystack to raise the configuration errors.
is there any reason to keep the error handling in:
- this check?
BillSearchSubscription.get_updates
?send_notifications
?
(apologies if this is obvious, i may need some more caffeine.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To me, these extra checks seem like reasonable defensive programming in the face of an uncertain integration. We expect Haystack to raise a configuration error if its configuration dictionary is not properly defined, but we also don't control Haystack or its startup logic, so we can't have perfect confidence that it will error out when we want it to. Plus, when we access HAYSTACK_URL
, it's in a nested dictionary on the settings
object, so if any part of settings.HAYSTACK_CONNECTIONS['default']['URL']
is not defined the user will get a super unhlpeful error. Does this judgment seem reasonable to you, or do you think it's overly confusing to be extra cautious around HAYSTACK_URL
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
while it's true we don't control haystack, we do control the version of haystack we want to run, so we have a way of ensuring consistency if future releases of haystack behave differently than the one we're using now, which does raise the configuration error as we expect.
that said, i do find more useful exceptions a compelling reason to preserve the custom exception handling code. this isn't a change i require.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your comments @hancush! I followed up with a couple questions for you. For the ones that have immediate action steps, I'll go ahead and make the changes and then re-request your review.
from django.contrib.postgres.fields import JSONField | ||
try: | ||
HAYSTACK_URL = settings.HAYSTACK_CONNECTIONS['default']['URL'] | ||
except KeyError: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like that idea a lot, but do you have any sense of how we'd hook into the app start event to emit the warning? Not sure when that happens and I can't find anything from a cursory search.
… be local to handle()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@hancush I think I responded to all of your comments! Look like there's anything I missed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
although it was bigger than anticipated, this is a better refactor than i could have imagined! great work, @jeancochrane, and thank you. i left a couple of comments inline, but i'm happy to approve.
cursor.execute(new_bills, [ocd_ids]) | ||
|
||
bills = [] | ||
def _is_empty(self, elem): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does this lil guy need to stick around now that you've defined it locally?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops, great catch! Removed in f74e508.
from django.contrib.postgres.fields import JSONField | ||
try: | ||
HAYSTACK_URL = settings.HAYSTACK_CONNECTIONS['default']['URL'] | ||
except KeyError: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think we we landed on the app not being able to run without search, i.e., we can rely on haystack to raise the configuration errors.
is there any reason to keep the error handling in:
- this check?
BillSearchSubscription.get_updates
?send_notifications
?
(apologies if this is obvious, i may need some more caffeine.)
Overview
Make sure the app is compatible with
django-councilmatic
v2.5. The major changes in this update include:send_notifications
management command to use the ORM and the new OCD model structureNotes
Testing instructions
pip install -e .[tests]
pytest
and confirm all tests pass