{"push_id":2739089867,"size":1,"distinct_size":1,"ref":"refs/heads/fix-29467","head":"53ef9ce8a20e1bd45e016f7e02e57f50e68d67f5","before":"b3444ece6aba722d25413a9c540d62a4d123d8b3","commits":[{"sha":"53ef9ce8a20e1bd45e016f7e02e57f50e68d67f5","author":{"name":"Sławek Ehlert","email":"4fad7f082d0a82b3c401e5e5c7d5bbf2c2ddfe69@op.pl"},"message":"Fixed #29467\n\nMade override_settings handle errors in setting_changed signal receivers.\n\nCheck 3 things when using `override_settings`:\n1. It returns the receiver exception\n   when at least one of the receivers fail.\n2. It restores original settings when exception occurs.\n3. It calls *every* receiver when exiting the context\n   and reraises the first exception that occured.\n\nCheck that for 3 cases of exception occurance in the receiver\n- exception occurs when a receiver is called with `enter=True`\n- exception occurs when a receiver is called with `enter=False`\n- exception occurs regardless of the `enter` keyword argument.\n\nI've introduced 4 custom and (hopefully) unique setting names\nand used them for testing.\n\nA receiver handles those settings:\n- `SETTING_BOTH` raises an error while receiving the\n  signal on both entering and exiting the context manager\n- `SETTING_ENTER` raises an error only on enter.\n- `SETTING_EXIT` raises an error only on exit.\n- `SETTING_PASS` passes without errors.\n\n*Re: 1. It returns the receiver exception...*\n\nBecause \"errors should never pass silently\".\n\n*Re: 2. It restores original settings when exception occurs.*\n\nI think that's pretty obvious - that's the main pain point of #29467\n\n*Re: 3. It calls every receiver when exiting the context...*\n\nOne of the patterns for connecting to the `setting_changed` signal is to\nprepare a valid environment when the change occurs and clean it up when\nthe setting is restored (e.g. see `django.test.signals` module).\nWhen an exception occurs while entering the `override_settings`\ncontext manager we want to make sure to propagate that error,\nbut also it makes sense to ensure that every receiver is called when\nexiting the context so that receivers have a chance to clean up after\nthemselves.\n\n**Example:**\n\nGiven a list of receivers for `setting_changed` signal:\n- a receiver X that fails only when passed `enter=False`,\n- `django.test.signals.static_finders_changed`,\n- others.\n\nWhile calling e.g. `override_settings(STATIC_ROOT=new_path)`\nwe want to make sure that outside of that manager we not only have\nrestored the `STATIC_ROOT` setting after receiver X failed,\nbut also that we've cleared the cache for staticfiles finder.\n\nSimilar examples could be made with most of the receivers from\n`django.test.signals` module.\n\nhttps://code.djangoproject.com/ticket/29467","distinct":true,"url":"https://api.github.com/repos/slafs/django/commits/53ef9ce8a20e1bd45e016f7e02e57f50e68d67f5"}]}
{"actor":{"display_login":"slafs"}}