Alex Rivera | Logout

Transaction managed block ended with pending COMMIT/ROLLBACK

Asked 2011-04-13T10:27:13.307
31

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.

Edit
Report

1 Answer

1

I had similar problem, maybe this code works fine for you:

@transaction.commit_on_success
def xyz(request):
    if ABC:
        success = something()

        if success:
            status = "success"

        else:
            status = "dataerrors"
            transaction.rollback()
    else:
        status = "uploadproblem"
        transaction.rollback()

    return render(request, "template.html", {
        'status': status,
    })
answered 2012-02-06T16:05:06.240

Your Answer