Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Model.refresh_from_db() does not update _fieldsignals_originals #17

Open
ajhodges opened this issue Jul 19, 2019 · 1 comment
Open

Model.refresh_from_db() does not update _fieldsignals_originals #17

ajhodges opened this issue Jul 19, 2019 · 1 comment

Comments

@ajhodges
Copy link

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.

@craigds
Copy link
Owner

craigds commented Jul 27, 2019

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants