django-fieldsignals
django-fieldsignals copied to clipboard
Model.refresh_from_db() does not update _fieldsignals_originals
I have some unit tests that use refresh_from_db to update the state of a model instance throughout a unit test. In one of my tests, I update the state of a field (that has a fieldsignal attached) via Django/API call, and then refresh that instance in my test function. The field is updated with the new value (that was set via API) on my instance, but _fieldsignals_originals is never updated from the old value. So the next time I call instance.save(), the signal fires even if there has not been an additional update to the field (and the signal gets passed incorrect values for (old, new)).
I may or may not take a shot at a fix for this - any ideas? I probably will just rework my unit tests to avoid this scenario for now.
Unfortunately I don't think there's a way to support this with signals on current Django. The only way at present would be to add a Model subclass and override Model.refresh_from_db.
I've added a ticket for adding a signal in Django: https://code.djangoproject.com/ticket/30662