#35890: pre_save field in parent models are not called during update in
update_or_create
-------------------------------------+-------------------------------------
     Reporter:  Gagaro               |                    Owner:  (none)
         Type:  Bug                  |                   Status:  new
    Component:  Database layer       |                  Version:  dev
  (models, ORM)                      |
     Severity:  Normal               |               Resolution:
     Keywords:                       |             Triage Stage:  Accepted
    Has patch:  1                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  1
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
Changes (by Simon Charette):

 * needs_better_patch:  0 => 1
 * stage:  Unreviewed => Accepted

Comment:

 I see no reasons why this should only work for local concrete fields given
 `update_or_create` works with MTI.

 There's a nuance not captured in the patch though that I believe should be
 addressed at the same time. Only pre-save fields for the model associated
 with at-least-one update field should be augmented. What I mean by that is
 that given the following models

 {{{#!python
 class Location(models.Model):
     location_updated_at = models.DateTimeField(auto_now=True)
     location_street = models.TextField()

 class Restaurant(Location):
     restaurant_updated_at = models.DateTimeField(auto_now=True)
     menu = models.JSONField()
 }}}

 Then

 {{{#!python
 Restaurant.objects.update_or_create(
    ...,
    defaults={"menu": ...}  # Only restaurant_updated_at should be included
 in `update_fields`
 )
 Restaurant.objects.update_or_create(
    ...,
    defaults={"location_street": ...}  # Only location_updated_at should be
 included in `update_fields`
 )
 Restaurant.objects.update_or_create(
    ...,
    defaults={"menu": ..., "location_street": ...}  # Both
 restaurant_updated_at and location_updated_at should be included in
 `update_fields`
 )
 }}}
-- 
Ticket URL: <https://code.djangoproject.com/ticket/35890#comment:3>
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/01070193023117ee-0b559ce1-82ee-4198-af5d-52eb755fd4c7-000000%40eu-central-1.amazonses.com.

Reply via email to