#31315: Closing all connections in function tagged with @transaction_atomic or
transaction atomic block breaks atomicity
-------------------------------------+-------------------------------------
Reporter: David Eling | Owner: nobody
Type: Bug | Status: closed
Component: Database layer | Version: 2.1
(models, ORM) |
Severity: Normal | Resolution: wontfix
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Carlton Gibson):
* status: new => closed
* resolution: => wontfix
Comment:
Hi David. Thanks for the report. Interesting... :)
I think this is expected behaviour.
[https://docs.djangoproject.com/en/3.0/topics/db/sql/#connections-and-
cursors The docs go as far as]:
> `connection` and `cursor` mostly implement the standard Python DB-API
described in PEP 249
[https://www.python.org/dev/peps/pep-0249/#Connection.close That defines
the behaviour for `close()`]:
> Note that closing a connection without committing the changes first will
cause an implicit rollback to be performed.
[https://github.com/django/django/blob/d4fff711d4c97356bd6ba1273d2a5e349326eb5f/django/db/backends/base/base.py#L296-L298
Looking at the code], we have exactly that:
{{{
if self.in_atomic_block:
self.closed_in_transaction = True
self.needs_rollback = True
}}}
> Within our code base we had to isolate the offending bit and do it
before entering the atomic block.
I think that's the right approach. My first guess reading this would be
that closing the connection inside a transaction would be at best
undefined. ''What do I expect to happen there?'' — I could see a few
answers to that. That it's ''rollback'' is no real surprise.
I hope that makes sense?
Kind Regards,
Carlton
--
Ticket URL: <https://code.djangoproject.com/ticket/31315#comment:1>
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 on the web visit
https://groups.google.com/d/msgid/django-updates/065.25d299b270e40dc7ab643c68757ff1eb%40djangoproject.com.