Opened 13 years ago

Closed 13 years ago

Last modified 13 years ago

#15317 closed (invalid)

TransactionManagementError exception on a clean transaction

Reported by: Jerzy Ludwichowski Owned by: nobody
Component: Database layer (models, ORM) Version: dev
Severity: Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

I have a simple test view decorated with a transaction.commit_manually. The view does only a few database (MySQL) reads. Before returning I do a transaction.commit() and surely the call to transaction.is_dirty() returns False.

A further test with all database reads removed yields the same result.

My Django installation is at SVN 15540.

Change History (2)

comment:1 by Russell Keith-Magee, 13 years ago

Resolution: invalid
Status: newclosed

Sounds like you've been tripped up by r15493. However, since you haven't provided any details that would allow us to reproduce your problem, I can't confirm or deny this.

If you are reporting a problem, you need to provide enough detail for someone else to reproduce the problem *exactly*. It's no good giving vague descriptions -- we need specific code samples, or at the very least, precise instructions that will allow someone else to reproduce the problem you are seeing.

Closing invalid. Please reopen if you can provide the necessary detail.

in reply to:  1 comment:2 by Jerzy Ludwichowski, 13 years ago

Replying to russellm:

Sounds like you've been tripped up by r15493. However, since you haven't provided any details that would allow us to reproduce your problem, I can't confirm or deny this.

If you are reporting a problem, you need to provide enough detail for someone else to reproduce the problem *exactly*. It's no good giving vague descriptions -- we need specific code samples, or at the very least, precise instructions that will allow someone else to reproduce the problem you are seeing.

Closing invalid. Please reopen if you can provide the necessary detail.

Indeed, I was quite vague. My test view was:

@transaction.commit_manually
def test(request):
    return render_to_response("bdo/test.html", RequestContext(request))

and it failed in my environment with the TransactionManagementError exception. When trying to further minimize the example for the purpose of reopening this ticket, I removed the call to RequestContext like so:

@transaction.commit_manually
def test(request): 
    return render_to_response("bdo/test.html")

and then the view passed.
It turned out that I have a custom context processor which accesses the database to determine the menu functions available to the logged on user thus dirtying the transaction. I now do a conditional transaction.commit() in the context processor:

def create_menu(request):
   # ...
   # a database read
   if transaction.is_managed() :
      transaction.commit()
   # ...

which seems to solve the problem.

So it turns out that the ticket as stated is indeed invalid. Nonetheless, to prevent others tripping over in similar circumstances it might be helpful to amend at least the 1.3 release notes (http://docs.djangoproject.com/en/dev/releases/1.3/#transaction-management) and perhaps also the Managing database transactions section of the documentation (http://docs.djangoproject.com/en/dev/topics/db/transactions/). Sorry for not providing a sample wording...

Version 0, edited 13 years ago by Jerzy Ludwichowski (next)
Note: See TracTickets for help on using tickets.
Back to Top