#30319: model.save() surprising behavior with update_fields specified and
auto_now
field in model
-------------------------------------+-------------------------------------
Reporter: sebhaase | Owner: nobody
Type: | Status: new
Uncategorized |
Component: Database | Version: 2.1
layer (models, ORM) |
Severity: Normal | Keywords:
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
In section "Specifying which fields to save"
([https://docs.djangoproject.com/en/dev/ref/models/instances/#specifying-
which-fields-to-save]) it reads that `update_fields` can be specified
mostly for performance benefits...
However, I found that regarding a field with `auto_now=True` there is a
different outcome.
IOW, specifying `update_fields` can be used to keep the old date in
respective "auto_now=True"-field UNLESS that field is also explicitly
given un `update_fields`
This should be more prominently stated in the documentation.
In addition I also noticed that - using deserialization - `object.save()`
gives unexpected different results for auto_now field:
- if the object-pk already exists , the field is saved as given
- but if it does not exist, the given value is ignored, and the current
time is used instead
... very strange if you ask me...
refs:
[https://stackoverflow.com/questions/17474057/enforce-auto-now-when-using-
saveupdate-fields]
[https://groups.google.com/d/msg/django-users/sqMrUlZP2-8/FczIEwwMBAAJ]
--
Ticket URL: <https://code.djangoproject.com/ticket/30319>
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 post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/051.567b7d1f10a8db93dee6e87a7e0bf1db%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.