#34099: update_or_create() not saving data assigned in a model's save() method
-------------------------------------+-------------------------------------
     Reporter:  Phil Gyford          |                    Owner:  nobody
         Type:  Bug                  |                   Status:  new
    Component:  Database layer       |                  Version:  dev
  (models, ORM)                      |
     Severity:  Release blocker      |               Resolution:
     Keywords:                       |             Triage Stage:  Accepted
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
Changes (by Simon Charette):

 * cc: Simon Charette (added)


Comment:

 > But since update_fields was not so important in the past I can imagine
 users not implementing it leading to bugs that are not discovered for a
 while etc…

 I would argue that it was always important even before the
 `update_or_create` changes reliance was introduced.

 For example, when partially fetching model instance fields (e.g. using
 `only`) then
 
[https://github.com/django/django/blob/de2c2127b66e77a034c01c81753c5c08e651a5b4/django/db/models/base.py#L793-L802
 only the fetched fields will be updated] which
 
[https://docs.djangoproject.com/en/4.1/ref/models/querysets/#django.db.models.query.QuerySet.defer
 is documented].

 If we believe that documenting how to properly override `Model.save` or
 deal with `post_save` signal wrt/ to `update_fields` is not enough the
 only deprecation path I can think of that doesn't involve adding a setting
 is to add a temporary `__save_update_fields=False` kwarg to
 `update_or_create` and when `__save_update_fields is False` and `save() `
 is overridden or `post_save` signals are connected emit a deprecation
 warning and don't pass `update_fields`. That would allow callers to pass
 `__save_update_fields=True` to opt-in the new behaviour and silence the
 warning.

 This all seems like a lot of work for little benefit to me though given we
 didn't take this extra precautions when introducing `update_fields` in the
 first place in Django 1.5 and code that fails to account for this feature
 has been subtly broken since then.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/34099#comment:10>
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/010701841ab2817a-9b7c5759-67a3-4e07-9bad-f041fc1cd862-000000%40eu-central-1.amazonses.com.

Reply via email to