[Django] #23353: TransactionManagmentError isn't helpful for tracking down cause

16 views
Skip to first unread message

Django

unread,
Aug 23, 2014, 6:32:33 AM8/23/14
to django-...@googlegroups.com
#23353: TransactionManagmentError isn't helpful for tracking down cause
----------------------------------------------+--------------------
Reporter: mbox | Owner: nobody
Type: Bug | Status: new
Component: Database layer (models, ORM) | Version: master
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
----------------------------------------------+--------------------
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.

--
Ticket URL: <https://code.djangoproject.com/ticket/23353>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Aug 23, 2014, 10:38:01 AM8/23/14
to django-...@googlegroups.com
#23353: TransactionManagmentError isn't helpful for tracking down cause
-------------------------------------+-------------------------------------

Reporter: mbox | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: master
(models, ORM) | Resolution:
Severity: Normal | Triage Stage: Accepted
Keywords: | Needs documentation: 0
Has patch: 0 | Patch needs improvement: 0
Needs tests: 0 | UI/UX: 0
Easy pickings: 0 |
-------------------------------------+-------------------------------------
Changes (by aaugustin):

* needs_better_patch: => 0
* needs_docs: => 0
* needs_tests: => 0
* stage: Unreviewed => Accepted


Comment:

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

--
Ticket URL: <https://code.djangoproject.com/ticket/23353#comment:1>

Django

unread,
Aug 23, 2022, 11:24:24 AM8/23/22
to django-...@googlegroups.com
#23353: TransactionManagmentError isn't helpful for tracking down cause
-------------------------------------+-------------------------------------
Reporter: Malcolm Box | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: dev
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Simon Charette):

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

--
Ticket URL: <https://code.djangoproject.com/ticket/23353#comment:2>

Django

unread,
Oct 2, 2022, 1:12:54 PM10/2/22
to django-...@googlegroups.com
#23353: TransactionManagmentError isn't helpful for tracking down cause
-------------------------------------+-------------------------------------
Reporter: Malcolm Box | Owner: David
| Wobrock
Type: Bug | Status: assigned

Component: Database layer | Version: dev
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by David Wobrock):

* cc: David Wobrock (added)
* owner: nobody => David Wobrock
* has_patch: 0 => 1
* status: new => assigned


Comment:

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

Here's a patch [https://github.com/django/django/pull/16143 PR]

--
Ticket URL: <https://code.djangoproject.com/ticket/23353#comment:3>

Django

unread,
Oct 3, 2022, 12:12:10 AM10/3/22
to django-...@googlegroups.com
#23353: TransactionManagmentError isn't helpful for tracking down cause
-------------------------------------+-------------------------------------
Reporter: Malcolm Box | Owner: David
| Wobrock
Type: Bug | Status: assigned
Component: Database layer | Version: dev
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Ready for
| checkin

Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* stage: Accepted => Ready for checkin


--
Ticket URL: <https://code.djangoproject.com/ticket/23353#comment:4>

Django

unread,
Oct 3, 2022, 1:58:57 AM10/3/22
to django-...@googlegroups.com
#23353: TransactionManagmentError isn't helpful for tracking down cause
-------------------------------------+-------------------------------------
Reporter: Malcolm Box | Owner: David
| Wobrock
Type: Bug | Status: closed

Component: Database layer | Version: dev
(models, ORM) |
Severity: Normal | Resolution: fixed

Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak <felisiak.mariusz@…>):

* status: assigned => closed
* resolution: => fixed


Comment:

In [changeset:"3b4a5b9f97f113ca5151cff744019e39a1ed7475" 3b4a5b9f]:
{{{
#!CommitTicketReference repository=""
revision="3b4a5b9f97f113ca5151cff744019e39a1ed7475"
Fixed #23353 -- Used "raise from" when raising TransactionManagementError.

This change sets the __cause__ attribute to raised exceptions.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/23353#comment:5>

Reply all
Reply to author
Forward
0 new messages