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

refresh_from_db does not reset old values #136

Open
sjamaan opened this issue Aug 14, 2020 · 0 comments
Open

refresh_from_db does not reset old values #136

sjamaan opened this issue Aug 14, 2020 · 0 comments

Comments

@sjamaan
Copy link
Contributor

sjamaan commented Aug 14, 2020

I would expect foo.refresh_from_db() to exhibit exactly the same behaviour as foo = Foo.objects.get(pk=foo.pk), but foo.get_old_value('blabla') returns the original old value. Here's a sample from a test in an actual project where I wanted to test a validation check is only run when the type or status field changes.

		activity = activity_model(
			type='other', status='finished', finished_datetime='2017-10-14T13:00:00Z',
			start_km=0, end_km=0, start_fuel_level=0, end_fuel_level=0,
			assignment=assignment, allocation=allocation,
		)

		# Hack around a validation which triggers only if type changes by doing a bulk db query to change the type
		Activity.objects.filter(id=activity.id).update(type='load')

		activity.refresh_from_db()
		activity.get_old_value('status') # This returns "other", I would expect "load"

		activity = Activity.objects.get(id=activity.id)
		activity.get_old_value('status') # This returns "load", as expected
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

1 participant