Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Transaction managed block ended with pending COMMIT/ROLLBACK

I have a view function:

@transaction.commit_manually def xyz(request):     if ABC:         success = something()          if success:             status = "success"             transaction.commit()          else:             status = "dataerrors"             transaction.rollback()     else:         status = "uploadproblem"         transaction.rollback()      return render(request, "template.html", {         'status': status,     }) 

I believe every code path ends the transaction one way or another. But Django seems to be complaining that it doesn't. Any ideas?

Django Version:     1.3 Exception Type:     TransactionManagementError Exception Value:    Transaction managed block ended with pending COMMIT/ROLLBACK 

EDIT: No other exceptions are being thrown to alter the code path.

like image 496
Joe Avatar asked Apr 13 '11 10:04

Joe


1 Answers

After getting a similar issue and wasting hours on it I figured out how to debug this situation.

For some reason the @transaction.commit_manually decorator silences exceptions that occur in the function.

Temporarily remove the decorator from your function, you'll now see the exception, fix it and put the decorator back!

like image 106
Gert Steyn Avatar answered Oct 04 '22 00:10

Gert Steyn