#2259: PK Change creates new object instead of update
-------------------------------------+-------------------------------------
Reporter: ed@… | Owner: nobody
Type: Bug | Status: reopened
Milestone: | Component: contrib.admin
Version: | Severity: Normal
Resolution: | Keywords:
Triage Stage: Design | Has patch: 1
decision needed | Needs tests: 0
Needs documentation: 1 | Easy pickings: 0
Patch needs improvement: 1 |
UI/UX: 0 |
-------------------------------------+-------------------------------------
Comment (by akaariai):
I have been thinking about this a bit... And to me it seems entirely clear
that the current situation where changing primary key inserts a new record
is not acceptable if/when composite primary keys are included in Django.
Composite primary keys mean more use of natural primary keys, and they do
have the habit of changing.
Here is an example why the current situation must be changed. Consider a
person model with a pk of first_name, last_name and the following code:
{{{
p = Person.objects.get(first_name='John', last_name='Smith')
p.first_name = 'Jack'
p.save()
}}}
Who expects that to end up with John and Jack in the DB?
As I see it, there are two choices:
1. Throw an error when saving an object with PK changed. The error should
say that Django does not know what you want in this situation, use kwargs
to specify the wanted action.
2. Make Django intelligent enough to just do the right thing. My patch
above tries to do that but I am afraid it is not good enough.
In both cases new kwargs to save are needed to make it possible to
specify/override the action on save().
I favor choice 1. Choice 2 will mean complicating the logic of save_base.
Also, can Django guess the right action in every case?
My suggestion: deprecate current behavior of save() in 1.4.
--
Ticket URL: <https://code.djangoproject.com/ticket/2259#comment:22>
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 post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/django-updates?hl=en.