Opened 10 years ago

Closed 10 years ago

#11076 closed (duplicate)

@transaction.commit_on_success does not seem to work as documented

Reported by: Pierre Owned by: nobody
Component: Database layer (models, ORM) Version: 1.0
Severity: Keywords: @commit_on_success, set_dirty
Cc: Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


Observed on 1.0.2, but seems to be the same on 1.1.

Note that this is similar to ticket #9964, but not identical (the
issue presented here is much narrower).

I'm working on a simple view using the @transaction.commit_on_success

The view does UPDATE requests to a legacy database (through a custom
Python module).

Sample code (simplified)

def myview(request):
  # ...
  if request.method == "POST":
    # no Django model calls;
    # some calls causing an UPDATE
  # ...
  return render_to_response(...)

The work is always rolled-back by Django at the end of the view.

From django.db.transaction it appears that the commit() is done
only if a call to set_dirty() has been made previously:

                if is_dirty():

Which in my case does not happen (unless I call it explicitly, of
The documentation states:

If the function returns successfully, then Django will commit all work done
within the function at that point. If the function raises an exception, though, Django will
roll back the transaction.

As compared with the description of autocommit, which states things
explicitly, this seems to imply that the commit() is done in all
cases, dirty or not, so I found the actual behaviour surprising.

I don't know where is the best place to fix this, code or doc, but
in case you think it's the code... see attached patch :-)

Attachments (1)

transaction.diff (582 bytes) - added by Pierre 10 years ago.
patch for django/db/

Download all attachments as: .zip

Change History (3)

Changed 10 years ago by Pierre

Attachment: transaction.diff added

patch for django/db/

comment:1 Changed 10 years ago by Alex Gaynor

Dupe of #9964

comment:2 Changed 10 years ago by Alex Gaynor

Resolution: duplicate
Status: newclosed
Note: See TracTickets for help on using tickets.
Back to Top