#35127 closed Bug (fixed)
Model.full_clean() errors with GeneratedField
| Reported by: | Claude Paroz | Owned by: | Mariusz Felisiak |
|---|---|---|---|
| Component: | Database layer (models, ORM) | Version: | 5.0 |
| Severity: | Release blocker | Keywords: | |
| Cc: | Mariusz Felisiak, Lily Foote, Paolo Melchiorre | Triage Stage: | Accepted |
| Has patch: | yes | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description
When running full_clean() on an unsaved model instance, the folllowing error is generated:
AttributeError: Cannot read a generated field from an unsaved model.
Reproducible with following test:
--- a/tests/model_fields/test_generatedfield.py
+++ b/tests/model_fields/test_generatedfield.py
@@ -177,6 +177,10 @@ class GeneratedFieldTestMixin:
with self.assertRaises(IntegrityError):
self.base_model.objects.create()
+ def test_full_clean(self):
+ m = self.base_model(a=2, b=4)
+ m.full_clean()
+
def test_save(self):
# Insert.
m = self.base_model(a=2, b=4)
Change History (5)
comment:1 by , 22 months ago
| Cc: | added |
|---|---|
| Severity: | Normal → Release blocker |
| Triage Stage: | Unreviewed → Accepted |
comment:2 by , 21 months ago
| Owner: | changed from to |
|---|---|
| Status: | new → assigned |
Note:
See TracTickets
for help on using tickets.
Hello, thank you for your report! And thank you for providing a failing test.
I'm accepting given the failing test and that there is nothing in the docs stating that
full_cleanwould not be supported for models including aGeneratedFields, so while more expert input is needed (adding them as CC), this seems like a valid issue.Regression in f333e3513e8bdf5ffeb6eeb63021c230082e6f95