﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
30457	on_commit should be triggered in a TestCase	Bernhard Mäder	Adam Johnson	"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?"	New feature	closed	Testing framework	dev	Normal	fixed	on_commit TestCase	Simon Charette François Freitag Adam Johnson Florian Demmer	Ready for checkin	1	0	0	0	0	0
