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.
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!