Re: [Django] #35575: Add support for constraint validation on GeneratedFields (was: Model.full_clean() does not recalculate GeneratedFields prior to validating model constraints)

1 view
Skip to first unread message

Django

unread,
Jul 3, 2024, 12:29:39 PM (2 days ago) Jul 3
to django-...@googlegroups.com
#35575: Add support for constraint validation on GeneratedFields
-------------------------------------+-------------------------------------
Reporter: Mark Gensler | Owner: Mark
| Gensler
Type: New feature | Status: assigned
Component: Database layer | Version: 5.0
(models, ORM) |
Severity: Normal | Resolution:
Keywords: generatedfield | Triage Stage: Accepted
uniqueconstraint checkconstraint |
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Sarah Boyce):

* cc: Mariusz Felisiak, Lily Foote, Simon Charette (added)
* stage: Unreviewed => Accepted
* summary:
Model.full_clean() does not recalculate GeneratedFields prior to
validating model constraints
=> Add support for constraint validation on GeneratedFields
* type: Bug => New feature

Comment:

Replying to [comment:1 Mark Gensler]:
> Before writing any code to address this, I'd like to discuss ''where''
best to apply the fix. I see two possible options:
>
> 1. Recalculate `GeneratedField` attribute values on the fly as part of
calling `Constraint.validate()`. This will leave the instance attributes
unchanged until `Model.save()` is called.
> 2. Recalculate `GeneratedField` attributes on the model instance during
`Model.full_clean()`, prior to calls to `Constraint.validate()`, and
irrespective of whether relevant constraints are present.

My gut says option 1
--
Ticket URL: <https://code.djangoproject.com/ticket/35575#comment:4>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
Reply all
Reply to author
Forward
0 new messages