예제 #1
0
 def _handle_nested(self):
     """The NESTED propagation policy would commit all changes in the outer
     and inner transactions together when the outer policy commits. However,
     if an exception is thrown in the inner transaction all changes there
     would get thrown out but allow the outer transaction to optionally
     recover and continue. The NESTED policy is not supported. If you use
     this policy, your code will throw a BadRequestError exception.
     """
     raise exceptions.BadRequestError(
         "Nested transactions are not supported.")
예제 #2
0
 def _handle_mandatory(self):
     """Always propagate an existing transaction; throw an exception if
     there is no existing transaction. If a function that uses this policy
     throws an exception, it's probably not safe to catch the exception and
     commit the outer transaction; the function may have left the outer
     transaction in a bad state.
     """
     if not in_transaction():
         raise exceptions.BadRequestError(
             "Requires an existing transaction.")
예제 #3
0
        def non_transactional_inner_wrapper(*args, **kwargs):
            from . import context

            ctx = context.get_context()
            if not ctx.in_transaction():
                return wrapped(*args, **kwargs)
            if not allow_existing:
                raise exceptions.BadRequestError(
                    "{} cannot be called within a transaction".format(
                        wrapped.__name__))
            new_ctx = ctx.new(transaction=None)
            with new_ctx.use():
                return wrapped(*args, **kwargs)
예제 #4
0
        def non_transactional_inner_wrapper(*args, **kwargs):
            # Avoid circular import in Python 2.7
            from google.cloud.ndb import context as context_module

            context = context_module.get_context()
            if not context.in_transaction():
                return wrapped(*args, **kwargs)
            if not allow_existing:
                raise exceptions.BadRequestError(
                    "{} cannot be called within a transaction".format(
                        wrapped.__name__))
            new_context = context.new(transaction=None)
            with new_context.use():
                return wrapped(*args, **kwargs)