`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)
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/35127>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* cc: Mariusz Felisiak, Lily Foote, Paolo Melchiorre (added)
* severity: Normal => Release blocker
* stage: Unreviewed => Accepted
Comment:
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
`GeneratedField`s, so while more expert input is needed (adding them as
CC), this seems like a valid issue.
Regression in f333e3513e8bdf5ffeb6eeb63021c230082e6f95
--
Ticket URL: <https://code.djangoproject.com/ticket/35127#comment:1>
* owner: nobody => Mariusz Felisiak
* status: new => assigned
--
Ticket URL: <https://code.djangoproject.com/ticket/35127#comment:2>
* has_patch: 0 => 1
Comment:
[https://github.com/django/django/pull/17758 PR]
--
Ticket URL: <https://code.djangoproject.com/ticket/35127#comment:3>
* status: assigned => closed
* resolution: => fixed
Comment:
In [changeset:"4879907223d70ee1a82474d9286ccfa5dae96971" 4879907]:
{{{
#!CommitTicketReference repository=""
revision="4879907223d70ee1a82474d9286ccfa5dae96971"
Fixed #35127 -- Made Model.full_clean() ignore GeneratedFields.
Thanks Claude Paroz for the report.
Regression in f333e3513e8bdf5ffeb6eeb63021c230082e6f95.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/35127#comment:4>
Comment (by Mariusz Felisiak <felisiak.mariusz@…>):
In [changeset:"ee78fe390db7cf319f0ddc2de0c9190c783ef925" ee78fe3]:
{{{
#!CommitTicketReference repository=""
revision="ee78fe390db7cf319f0ddc2de0c9190c783ef925"
[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
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/35127#comment:5>