#34842: Unmanaged read-only generated fields in admin
-------------------------------------+-------------------------------------
Reporter: Paolo Melchiorre | Owner: Paolo
| Melchiorre
Type: Bug | Status: assigned
Component: contrib.admin | Version: dev
Severity: Release blocker | Resolution:
Keywords: field, database, | Triage Stage: Accepted
generated, admin |
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):
* owner: nobody => Paolo Melchiorre
* status: new => assigned
* stage: Unreviewed => Accepted
Comment:
Thanks for the report. What do you think about raising `AttributeError`
instead of `FieldError`?
{{{#!diff
diff --git a/django/db/models/query_utils.py
b/django/db/models/query_utils.py
index 9754864eef..4f3358eb8d 100644
--- a/django/db/models/query_utils.py
+++ b/django/db/models/query_utils.py
@@ -199,7 +199,7 @@ class DeferredAttribute:
val = self._check_parent_chain(instance)
if val is None:
if instance.pk is None and self.field.generated:
- raise FieldError(
+ raise AttributeError(
"Cannot read a generated field from an unsaved
model."
)
instance.refresh_from_db(fields=[field_name])
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/34842#comment:2>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/0107018a9886c2d4-0e1470be-b588-4648-87ff-411e01ba4e44-000000%40eu-central-1.amazonses.com.