#17341: Model.save() commits transactions after every parent class save
----------------------------------------------+--------------------
     Reporter:  akaariai                      |      Owner:  nobody
         Type:  Bug                           |     Status:  new
    Component:  Database layer (models, ORM)  |    Version:  1.3
     Severity:  Normal                        |   Keywords:
 Triage Stage:  Unreviewed                    |  Has patch:  1
Easy pickings:  0                             |      UI/UX:  0
----------------------------------------------+--------------------
 The bug is that when running outside transaction management, Django does a
 save() after every update/insert. In multitable inheritance, it is
 possible (although rare) that this will result in half-saved objects. For
 example, using postgresql, and model inheritance I get these queries:
 {{{
 BEGIN
 SELECT (1) AS "a" FROM "parent" WHERE "parent"."id" = 1  LIMIT 1
 UPDATE "parent" SET "f1" = 1 WHERE "parent"."id" = 1
 COMMIT -- Why commit here?
 BEGIN
 INSERT INTO "child" ("parent_ptr_id", "pk2") VALUES (1, NULL)
 ERROR:  null value in column "pk2" violates not-null constraint
 }}}
 Now I have committed a half-update. The attached patch gets rid of the
 COMMIT/BEGIN in the middle.

 I found this while hacking on #17332. It has more cleanups for .save (for
 example proxy handling), but I thought this deserves its own ticket.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/17341>
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.

Reply via email to