Opened 5 months ago

Closed 4 months ago

Last modified 4 months ago

#35560 closed Bug (fixed)

Model.full_clean() errors with GeneratedField and UniqueConstraint or CheckConstraint

Reported by: Mark Gensler Owned by: Mark Gensler
Component: Database layer (models, ORM) Version: 5.0
Severity: Release blocker Keywords: generatedfield uniqueconstraint checkconstraint
Cc: Mark Gensler, Mariusz Felisiak, Lily Foote, Paolo Melchiorre Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Calling full_clean() on an unsaved model instance which has either a UniqueConstraint or CheckConstraint raises the error:

AttributeError: Cannot read a generated field from an unsaved model.

This is similar to #35127.

The PR which will be attached shortly contains 4 new failing tests:

model_fields.test_generatedfield.GeneratedFieldTests.test_full_clean_with_unique_constraint
model_fields.test_generatedfield.GeneratedFieldTests.test_full_clean_with_check_constraint
model_fields.test_generatedfield.VirtualGeneratedFieldTests.test_full_clean_with_unique_constraint
model_fields.test_generatedfield.VirtualGeneratedFieldTests.test_full_clean_with_check_constraint

Change History (12)

comment:1 by Mark Gensler, 5 months ago

Summary: Model.full_clean() errors with when GeneratedField and UniqueConstraint or CheckConstraint are presentModel.full_clean() errors with GeneratedField and UniqueConstraint or CheckConstraint

comment:2 by Mark Gensler, 5 months ago

Has patch: set
Owner: changed from nobody to Mark Gensler
Status: newassigned

I've assigned this to myself as I'm happy to work on it. Will leave the discussion to the PR.

comment:3 by Mark Gensler, 5 months ago

Patch needs improvement: set

comment:4 by Natalia Bidart, 5 months ago

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

Hello Mark Gensler, thank you for this ticket report! And big thanks for the prompt PR.

comment:5 by Sarah Boyce, 4 months ago

Patch needs improvement: unset
Triage Stage: AcceptedReady for checkin

comment:6 by Sarah Boyce <42296566+sarahboyce@…>, 4 months ago

Resolution: fixed
Status: assignedclosed

In 1005c2a:

Fixed #35560 -- Made Model.full_clean() ignore GeneratedFields for constraints.

Accessing generated field values on unsaved models caused a crash when
validating CheckConstraints and UniqueConstraints with expressions.

comment:7 by Sarah Boyce <42296566+sarahboyce@…>, 4 months ago

In 2da00773:

[5.1.x] Fixed #35560 -- Made Model.full_clean() ignore GeneratedFields for constraints.

Accessing generated field values on unsaved models caused a crash when
validating CheckConstraints and UniqueConstraints with expressions.

Backport of 1005c2abd1ef0c156f449641e38c33e473989d37 from main.

comment:8 by Sarah Boyce <42296566+sarahboyce@…>, 4 months ago

In 0602fc2:

[5.0.x] Fixed #35560 -- Made Model.full_clean() ignore GeneratedFields for constraints.

Accessing generated field values on unsaved models caused a crash when
validating CheckConstraints and UniqueConstraints with expressions.

Backport of 1005c2abd1ef0c156f449641e38c33e473989d37 from main.

comment:9 by Sarah Boyce <42296566+sarahboyce@…>, 4 months ago

In c76089b:

[5.0.x] Refs #35560 -- Corrected CheckConstraint argument name in model_fields tests.

comment:10 by Sarah Boyce <42296566+sarahboyce@…>, 4 months ago

In 2d3bb414:

Refs #35560 -- Corrected required feature flags in GeneratedModelUniqueConstraint.

comment:11 by Sarah Boyce <42296566+sarahboyce@…>, 4 months ago

In ebcbf731:

[5.1.x] Refs #35560 -- Corrected required feature flags in GeneratedModelUniqueConstraint.

Backport of 2d3bb414cfb2778cc64f22e7203102d7389f81e6 from main.

comment:12 by Sarah Boyce <42296566+sarahboyce@…>, 4 months ago

In c1028bd:

[5.0.x] Refs #35560 -- Corrected required feature flags in GeneratedModelUniqueConstraint.

Backport of 2d3bb414cfb2778cc64f22e7203102d7389f81e6 from main.

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