#36318: Bad stack trace during rollback after bulk create
-------------------------------------+-------------------------------------
Reporter: Gordon Wrigley | Owner: (none)
Type: Bug | Status: new
Component: Database layer | Version: 4.2
(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'll point out that we document that weird things can happen when you
catch and handle exceptions inside an atomic block
Per
[https://docs.djangoproject.com/en/5.2/topics/db/transactions/#django.db.transaction.atomic
the docs]
> **Avoid catching exceptions inside atomic!
>
> When exiting an `atomic` block, Django looks at whether it’s exited
normally or with an exception to determine whether to commit or roll back.
If you catch and handle exceptions inside an atomic block, you may hide
from Django the fact that a problem has happened. **This can result in
unexpected behavior.**
I'm pretty confident we'll be able to avoid surfacing the previous
exception message as the source of the `TransactionManagementError` with
{{{#!diff
diff --git a/django/db/transaction.py b/django/db/transaction.py
index 0c2eee8e73..f56ecfc085 100644
--- a/django/db/transaction.py
+++ b/django/db/transaction.py
@@ -195,6 +195,7 @@ def __enter__(self):
# Reset state when entering an outermost atomic block.
connection.commit_on_exit = True
connection.needs_rollback = False
+ connection.rollback_exc = None
if not connection.get_autocommit():
# Pretend we're already in an atomic block to bypass the
code
# that disables autocommit to enter a transaction, and
make a
}}}
as this is a bug in #23353 (3b4a5b9f97f113ca5151cff744019e39a1ed7475) but
I'm afraid we won't able to have the `TransactionManagementError` provide
details about the `ValidationError` or any exception raised in an
exception handled inside an atomic block for that matter as it it doesn't
make it do `Atomic.__exit__` well it can't be stored anywhere.
--
Ticket URL: <https://code.djangoproject.com/ticket/36318#comment:4>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion visit
https://groups.google.com/d/msgid/django-updates/0107019625733aeb-ba224895-d50d-4993-990d-353218e1ce29-000000%40eu-central-1.amazonses.com.