#36855: Field.pre_save() called twice during save() in Django 6.0 when inserting
new records
-------------------------------------+-------------------------------------
     Reporter:  nino-robotfutures-   |                     Type:  Bug
  co                                 |                Component:  Database
       Status:  new                  |  layer (models, ORM)
      Version:  6.0                  |                 Severity:  Normal
     Keywords:                       |             Triage Stage:
                                     |  Unreviewed
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
 Commit 94680437 introduced a change where Field.pre_save() can be called
 twice during Model.save() for new records:

 Diff:
 
https://github.com/django/django/commit/94680437a45a71c70ca8bd2e68b72aa1e2eff337
 Full method:
 
https://github.com/django/django/blob/94680437a45a71c70ca8bd2e68b72aa1e2eff337/django/db/models/base.py#L1085-L1164

 Previously, pre_save() was only called once in the values comprehension.

 Impact:

 This is a breaking change for custom model fields that:
   - Have side effects in pre_save() (e.g., registering
 transaction.on_commit callbacks)
   - Transform the value in a way that's not idempotent
   - Maintain internal state based on pre_save() being called once per save

 Example:

   A custom field that registers an on_commit callback in pre_save() will
 now register it twice, causing the callback to execute twice.

 Expected behavior:

   Field.pre_save() should be called exactly once per Model.save()
 operation, regardless of whether the save results in an INSERT or UPDATE.
-- 
Ticket URL: <https://code.djangoproject.com/ticket/36855>
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 visit 
https://groups.google.com/d/msgid/django-updates/0107019ba35e45a2-0c7bbad5-383c-4a1d-ac93-edf149c96659-000000%40eu-central-1.amazonses.com.

Reply via email to