Opened 16 years ago
Closed 16 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 |
Description
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
decorator.
The view does UPDATE requests to a legacy database (through a custom
Python module).
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
course).
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)
Change History (3)
by , 16 years ago
Attachment: | transaction.diff added |
---|
comment:2 by , 16 years ago
Resolution: | → duplicate |
---|---|
Status: | new → closed |
patch for django/db/transaction.py