#29557: add on_commit decorator
-------------------------------------+-------------------------------------
     Reporter:  obayemi              |                    Owner:  nobody
         Type:  New feature          |                   Status:  new
    Component:  Uncategorized        |                  Version:  master
     Severity:  Normal               |               Resolution:
     Keywords:  transaction          |             Triage Stage:
  on_commit decorator                |  Unreviewed
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
Description changed by obayemi:

Old description:

> 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
> https://github.com/django/django/pull/10167

New description:

 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

--

-- 
Ticket URL: <https://code.djangoproject.com/ticket/29557#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 django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/065.23946bd42f38247afa98ade7b323a703%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to