#2259: PK Change creates new object instead of update
---------------------------------------------+------------------------------
          Reporter:  [email protected]          |         Owner:  nobody
            Status:  reopened                |     Milestone:        
         Component:  django.contrib.admin    |       Version:        
        Resolution:                          |      Keywords:        
             Stage:  Design decision needed  |     Has_patch:  0     
        Needs_docs:  1                       |   Needs_tests:  0     
Needs_better_patch:  1                       |  
---------------------------------------------+------------------------------
Changes (by carljm):

  * stage:  Accepted => Design decision needed

Comment:

 So after looking at this a bit on the flight yesterday, the tricky bit
 turns out to be referential integrity. As in, updating a PK breaks it, if
 there are any foreign keys pointing to that row. Which results in broken
 foreign keys on databases that don't enforce referential integrity, and an
 immediate IntegrityError on databases that do.

 For databases that support it, ON UPDATE CASCADE would fix this (which
 would mean this ticket blocks on #7539). Otherwise, we could manually
 emulate ON UPDATE CASCADE, which doen't actually sound terribly onerous
 (one query per referencing table), but is likely to be somewhat fiddly in
 practice and kinda gives me the willies.

 I don't see it as a viable option to provide a "feature" in the admin that
 breaks referential integrity in your database. So setting this back to
 DDN.

 I do have a patch that works fine, aside from the referential integrity
 problem, which I'll upload. I added an optional argument to Model.save()
 rather than using the .update() trick so as to make it work without adding
 any additional queries. This choice would be easy to reverse if the
 additional save arg is unacceptable, but not going to bother with that
 until the bigger issues are resolved.

-- 
Ticket URL: <http://code.djangoproject.com/ticket/2259#comment:18>
Django <http://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.

Reply via email to