﻿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
29557	add on_commit decorator	obayemi	nobody	"I recently had to add on_commit hooks with lambdas to some functions (mainly email notifications in post_save signals handler)
That was a lot of boilerplate so I wrote a simple decorator for making a function call only trigger on transaction commit

{{{
def call_on_commit(f):
    """"""
    only call the decorated function at transaction commit
    warning the return value will be ignored
    """"""
    def handle(*args, **kwargs):
        transaction.on_commit(lambda: f(*args, **kwargs))
    return handle
}}}

leading to

{{{
@call_on_commit
def send_message(user, context):
    # send message
}}}
instead of 
{{{
def send_message(user, context):
    def _send_message():
        # send message
    on_commit(do_stuff)
}}}

I made a PR on github to implement this feature if it seems relevant
https://github.com/django/django/pull/10167
"	New feature	closed	Database layer (models, ORM)	dev	Normal	wontfix	transaction on_commit decorator	Carlton Gibson	Unreviewed	1	1	1	0	1	0
