Opened 10 years ago

Closed 2 years ago

#23353 closed Bug (fixed)

TransactionManagmentError isn't helpful for tracking down cause

Reported by: Malcolm Box Owned by: David Wobrock
Component: Database layer (models, ORM) Version: dev
Severity: Normal Keywords:
Cc: David Wobrock Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

The error: "TransactionManagementError: An error occurred in the current transaction. You can't execute queries until the end of the 'atomic' block." thrown from django/db/backends/init.py", line 372, in validate_no_broken_transaction doesn't provide enough information to help track down the problem.

The exception is thrown if self.needs_rollback is True, but the underlying reason that self.needs_rollback has been set True has been lost, since it could have happened a long time previously.

Transactions should keep track of why needs_rollback has been set, and use that to provide a more helpful error.

Background: I'm seeing this error being thrown when a task is run on a Celery queue, but not when run manually. Since it's via Celery, dropping into the debugger is impossible, and thus I'm back to trying to dump useful debug info.

Change History (5)

comment:1 by Aymeric Augustin, 10 years ago

Triage Stage: UnreviewedAccepted

Accepting the general idea, but I'm not sure how that would work in practice.

comment:2 by Simon Charette, 2 years ago

I guess we could track the original exception and set it as the __cause__ of the TransactionManagementError.

comment:3 by David Wobrock, 2 years ago

Cc: David Wobrock added
Has patch: set
Owner: changed from nobody to David Wobrock
Status: newassigned

Beginners often struggle understanding the root cause when a TransactionManagementError occurs.

Here's a patch PR

comment:4 by Mariusz Felisiak, 2 years ago

Triage Stage: AcceptedReady for checkin

comment:5 by Mariusz Felisiak <felisiak.mariusz@…>, 2 years ago

Resolution: fixed
Status: assignedclosed

In 3b4a5b9f:

Fixed #23353 -- Used "raise from" when raising TransactionManagementError.

This change sets the cause attribute to raised exceptions.

Note: See TracTickets for help on using tickets.
Back to Top