#26787 closed Cleanup/optimization (fixed)
Accessing a deleted model field attribute triggers a query to reload the field rather than raising AttributeError (behavior change in 1.10)
Reported by: | Julien Hartmann | Owned by: | Tim Graham |
---|---|---|---|
Component: | Documentation | Version: | 1.10 |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Accepted | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description (last modified by )
This is a consequence of the implementation of #26207 in PR 6118
Now, all fields have a DeferredAttribute
descriptor. This has the consequence that this will trigger a model reload:
obj = MyModel.objects.get(pk=1) del obj.title obj.title
Up to version 1.9 (included), this code would raise an AttributeError
. Now it silently triggers a query to reload the field from the database.
Is this intended? If so, it should probably be added to the release notes.
Change History (9)
comment:1 by , 9 years ago
Description: | modified (diff) |
---|
comment:2 by , 9 years ago
comment:3 by , 9 years ago
Summary: | Access to deleted attribute triggers a query → Accessing a deleted model field attribute triggers a query to reload the field rather than raising AttributeError (behavior change in 1.10) |
---|
comment:4 by , 9 years ago
I don't have a use case.
I maintain a third-party package (django-hvad), that adds transparent model translation functionalities. To ensure behavior of hvad-enabled models is consistent with vanilla django models, I have extensive test cases in place. That's how I detected this change.
I went through the release notes and found nothing, so I decided to open a ticket. Documenting the change in behavior in the release notes is perfectly fine with me. :)
comment:5 by , 9 years ago
Component: | Database layer (models, ORM) → Documentation |
---|---|
Owner: | changed from | to
Status: | new → assigned |
Triage Stage: | Unreviewed → Accepted |
Type: | Uncategorized → Cleanup/optimization |
comment:7 by , 9 years ago
Great! So from the test case I understand it is guaranteed that only the accessed field is reloaded.
I'll update my own test case to check this as well. Support for Django v1.10 will be complete soon, thanks for being so reactive.
The description of that PR gives an example of the behavior you describe:
so I'd say that yes, that's what Anssi intended. Whether or not there's justification to change the behavior is another question, although the old behavior seems untested and undocumented so backwards-compatibility likely isn't extremely critical.
Could you explain your use case? Are there any ways to achieve it after the change?