#24921: No Database objects can be created with set_autocommit(False)
-------------------------------------+-------------------------------------
Reporter: shabda | Owner: shabda
Type: Bug | Status: new
Component: Database layer | Version: 1.8
(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 aaugustin):
`Atomic` is a context-manager / decorator in order to enforce proper
matching between `__enter__` and `__exit__` calls. If the calls aren't
balanced properly, data loss will happen, and it may be hard to diagnose.
That's why I've historically rejected the idea of exposing this methods
through public APIs.
Django uses the hack carljm suggests in its own test setUp / tearDown
functions. See `TestCase._enter_atomics` and `_rollback_atomics`. That's
exactly the OP's use case, so I suggest using that as a stop gap solution.
Don't forget to call `set_rollback(True)` before exiting, since you want a
rollback.
For the ORM to function with autocommit off, we should change the
`savepoint` parameter of `atomic` to add a third-value, `None` (three-
valued booleans, grrr), which would mean "automatic" and be implemented as
follows:
if self.savepoint is None:
self.savepoint = not connection.in_atomic_block and not
connection.get_autocommit()
In other words, it would mean "no savepoint, unless I'm the outermost
atomic block in a connection that is already in a transaction, which means
I can't use a plain transaction"
That's backwards incompatible. It just makes Django cope with a situation
where it would previously rais `TransactionManagementError`.
--
Ticket URL: <https://code.djangoproject.com/ticket/24921#comment:10>
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 post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/064.5d3bef88eef685f809f7c2cc75d73796%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.