[Django] #35127: Model.full_clean() errors with GeneratedField

19 views
Skip to first unread message

Django

unread,
Jan 18, 2024, 12:43:47 PM1/18/24
to django-...@googlegroups.com
#35127: Model.full_clean() errors with GeneratedField
-------------------------------------+-------------------------------------
Reporter: Claude | Owner: nobody
Paroz |
Type: Bug | Status: new
Component: Database | Version: 5.0
layer (models, ORM) |
Severity: Normal | Keywords:
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
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)
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/35127>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Jan 18, 2024, 1:24:32 PM1/18/24
to django-...@googlegroups.com
#35127: Model.full_clean() errors with GeneratedField
-------------------------------------+-------------------------------------
Reporter: Claude Paroz | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 5.0
(models, ORM) |
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Natalia Bidart):

* 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>

Django

unread,
Jan 18, 2024, 11:58:54 PM1/18/24
to django-...@googlegroups.com
#35127: Model.full_clean() errors with GeneratedField
-------------------------------------+-------------------------------------
Reporter: Claude Paroz | Owner: Mariusz
| Felisiak
Type: Bug | Status: assigned

Component: Database layer | Version: 5.0
(models, ORM) |
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* owner: nobody => Mariusz Felisiak
* status: new => assigned


--
Ticket URL: <https://code.djangoproject.com/ticket/35127#comment:2>

Django

unread,
Jan 19, 2024, 12:14:51 AM1/19/24
to django-...@googlegroups.com
#35127: Model.full_clean() errors with GeneratedField
-------------------------------------+-------------------------------------
Reporter: Claude Paroz | Owner: Mariusz
| Felisiak
Type: Bug | Status: assigned
Component: Database layer | Version: 5.0
(models, ORM) |
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* has_patch: 0 => 1


Comment:

[https://github.com/django/django/pull/17758 PR]

--
Ticket URL: <https://code.djangoproject.com/ticket/35127#comment:3>

Django

unread,
Jan 19, 2024, 2:56:01 AM1/19/24
to django-...@googlegroups.com
#35127: Model.full_clean() errors with GeneratedField
-------------------------------------+-------------------------------------
Reporter: Claude Paroz | Owner: Mariusz
| Felisiak
Type: Bug | Status: closed

Component: Database layer | Version: 5.0
(models, ORM) |
Severity: Release blocker | Resolution: fixed

Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by GitHub <noreply@…>):

* 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>

Django

unread,
Jan 19, 2024, 2:56:38 AM1/19/24
to django-...@googlegroups.com
#35127: Model.full_clean() errors with GeneratedField
-------------------------------------+-------------------------------------
Reporter: Claude Paroz | Owner: Mariusz
| Felisiak
Type: Bug | Status: closed
Component: Database layer | Version: 5.0
(models, ORM) |
Severity: Release blocker | Resolution: fixed
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

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>

Reply all
Reply to author
Forward
0 new messages