Transaction managed block ended with pending COMMIT/ROLLBACK
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!
I had the same problem. The only solution I found was to use a try/finally clause to ensure a commit happens after the render.
@transaction.commit_manually
def xyz(request):
committed = False
try:
if ABC:
success = something()
if success:
status = "success"
transaction.commit()
committed = True
else:
status = "dataerrors"
transaction.rollback()
committed = True
else:
status = "uploadproblem"
transaction.rollback()
committed = True
return render(request, "template.html", {
'status': status,
})
finally:
if not committed:
transaction.rollback() # or .commit() depending on your error-handling logic
Makes no sense, but it worked for me.