@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|
|Has patch:||yes||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||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
Sample code (simplified)
@transaction.commit_on_success 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(): commit()
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 :-)