﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
36344	Accessing a related field after using defer() or only() unexpectedly overwrites unsaved state on model instances	Erick		"When working with a model instance that was originally loaded with `only()` or `defer()`, accessing any related object not cached on the instance reverts unrelated fields to the value currently present in the database.

This toy example reproduces the behavior:

{{{
class SomethingElse(Model):
    ...

class Something(Model):
    foo = CharField(max_length=2)
    bar = CharField(max_length=2)
    other = ForeignKey(SomethingElse)


Something.objects.create(
    foo=""ab"",
    bar=""cd"",
    other=SomethingElse.objects.create()
)

something = Something.objects.only(""bar"").first()
something.foo = ""ef""
assert something.foo == ""ef""

something.other   # Accessing this deferred related field triggers the behavior
assert something.foo == ""ef""  # AssertionError
}}}

This is surprising behavior, because application code may interact with model instances without knowing how they were loaded from the database. "	Uncategorized	closed	Database layer (models, ORM)	5.2	Normal	invalid		Erick	Unreviewed	0	0	0	0	0	0
