You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
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 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 callinstance.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.
The text was updated successfully, but these errors were encountered: