#31071: Change in behaviour when saving a model instance with an explcit pk
value
if the pk field has a default
-------------------------------------+-------------------------------------
Reporter: Reupen Shah | Owner: Simon
| Charette
Type: Bug | Status: assigned
Component: Database layer | Version: 3.0
(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
-------------------------------------+-------------------------------------
Comment (by Simon Charette):
I'm afraid we'll have to revert 85458e94e38c20e57939947ee515a1a53689659f
if we want this pattern to work because we assign field defaults on
`Model.__init__` without tracking whether or not they were generated from
field defaults or not which makes both `Sample()` and `Sample(pk=s0.pk)`
have `pk_set=True` in `_save_table`.
Note that this limitation was mentioned in
https://code.djangoproject.com/ticket/29260#comment:3 so another option
could be to document that `force_update` must be used in this particular
case. I feel like this would be good compromise. Regarding the fixture
loading we should branch of `raw`
[https://github.com/django/django/blob/master/django/core/serializers/base.py#L219-L223
which is passed by the serialization framework] to disable the
optimiation.
Happy to provide a patch for whatever solution we choose. I think it's
worth adjusting the feature given and documenting it as a backward
incompatible change that be worked around by passing `force_update` but
simply reverting the feature and reopening #29260 to target the next
release is likely less trouble.
--
Ticket URL: <https://code.djangoproject.com/ticket/31071#comment:6>
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/064.1de4cd14937ddf60a3d89a16013d5d34%40djangoproject.com.