Opened 10 months ago

Closed 10 months ago

Last modified 10 months ago

#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 Natalia Bidart, 10 months ago

Cc: Mariusz Felisiak Lily Foote Paolo Melchiorre added
Severity: NormalRelease blocker
Triage Stage: UnreviewedAccepted

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_clean would not be supported for models including a GeneratedFields, so while more expert input is needed (adding them as CC), this seems like a valid issue.

Regression in f333e3513e8bdf5ffeb6eeb63021c230082e6f95

comment:2 by Mariusz Felisiak, 10 months ago

Owner: changed from nobody to Mariusz Felisiak
Status: newassigned

comment:3 by Mariusz Felisiak, 10 months ago

Has patch: set

comment:4 by GitHub <noreply@…>, 10 months ago

Resolution: fixed
Status: assignedclosed

In 4879907:

Fixed #35127 -- Made Model.full_clean() ignore GeneratedFields.

Thanks Claude Paroz for the report.

Regression in f333e3513e8bdf5ffeb6eeb63021c230082e6f95.

comment:5 by Mariusz Felisiak <felisiak.mariusz@…>, 10 months ago

In ee78fe3:

[5.0.x] Fixed #35127 -- Made Model.full_clean() ignore GeneratedFields.

Thanks Claude Paroz for the report.

Regression in f333e3513e8bdf5ffeb6eeb63021c230082e6f95.
Backport of 4879907223d70ee1a82474d9286ccfa5dae96971 from main

Note: See TracTickets for help on using tickets.
Back to Top