#35575: Model.full_clean() does not recalculate GeneratedFields prior to 
validating
model constraints
-------------------------------------+-------------------------------------
     Reporter:  Mark Gensler         |                    Owner:  Mark
                                     |  Gensler
         Type:  Bug                  |                   Status:  assigned
    Component:  Database layer       |                  Version:  5.0
  (models, ORM)                      |
     Severity:  Normal               |               Resolution:
     Keywords:  generatedfield       |             Triage Stage:
  uniqueconstraint checkconstraint   |  Unreviewed
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
Comment (by Mark Gensler):

 I'm happy to start working on this. I will raise a PR and add failing
 tests to catch the bug shortly.

 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.

 The second option would allow further checks against the new
 `GeneratedField` value of the instance to be made during validation. On
 the other hand, the first option would leave the instance's attribute
 returning the value currently returned/stored by the database.

 Which would be best?
-- 
Ticket URL: <https://code.djangoproject.com/ticket/35575#comment:1>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/0107019078352137-8bfdf4df-3398-466e-921a-c92b1e391c03-000000%40eu-central-1.amazonses.com.

Reply via email to