#30457: on_commit should be triggered in a TestCase
-------------------------------------+-------------------------------------
Reporter: Bernhard | Owner: nobody
Mäder |
Type: New | Status: new
feature |
Component: Testing | Version: 1.11
framework |
Severity: Normal | Keywords: on_commit TestCase
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
Testing code which uses `transaction.on_commit()` currently is
inconvenient and (for me) confusing, as `on_commit()` is never called
because of TestCase's outermost transaction.
We use something like this, woven into all those test, to run queued
commit hooks on demand:
{{{#!python
def run_commit_hooks():
for db_name in settings.DATABASES.keys():
connection = transaction.get_connection(using=db_name)
current_run_on_commit = connection.run_on_commit
connection.run_on_commit = []
while current_run_on_commit:
sids, func = current_run_on_commit.pop(0)
func()
}}}
This works, but is, of course, not optimal.
I wonder if there's a reason for this behaviour, is it intentional? As
those hooks are fully done within django, shouldn't it be possible to run
them when the second to the last transaction is committed?
--
Ticket URL: <https://code.djangoproject.com/ticket/30457>
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/049.30b0fd789ed4ca5fb8d8a3d34fae0522%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.