Hi,

I have a specific function with an transaction.commit_on_success


@transaction.commit_on_success
def f1():
   with transaction.commit_on_success:
      do_stuff()
      change_model_data_1 . . ,\.



and I have now another function

def f2():
   change_other_model_data()
   f1()


Now I would like to decorate f2() with

@transaction.commit_on_success

My  expected behaviour for my application would be, that the inner
transaction would be ignored in that case and be extended to the outer
transaction.


Are nested decorators supported with  Django 1.3  or should I write a
small wrapper as recommended in

http://djangosnippets.org/snippets/1343/

The suggested snippet is:

def nested_commit_on_success(func):
    """Like commit_on_success, but doesn't commit existing transactions.

    This decorator is used to run a function within the scope of a
    database transaction, committing the transaction on success and
    rolling it back if an exception occurs.

    Unlike the standard transaction.commit_on_success decorator, this
    version first checks whether a transaction is already active.  If so
    then it doesn't perform any commits or rollbacks, leaving that up to
    whoever is managing the active transaction.
    """
    commit_on_success = transaction.commit_on_success(func)
    def _nested_commit_on_success(*args, **kwds):
        if transaction.is_managed():
            return func(*args,**kwds)
        else:
            return commit_on_success(*args,**kwds)
    return transaction.wraps(func)(_nested_commit_on_success)


I'm asking as this snippet is already 3 years old.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to