Skip to content

refresh_from_db does not reset old values #136

@sjamaan

Description

@sjamaan

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions