def _transaction_ctx_for_context(context): by_thread = _transaction_contexts_by_thread(context) try: return by_thread.current except AttributeError: raise exception.NoEngineContextEstablished( "No TransactionContext is established for " "this %s object within the current thread. " % context)
def _property_for_context(context): try: transaction_context = context.transaction_ctx except exception.NoEngineContextEstablished: raise exception.NoEngineContextEstablished( "No TransactionContext is established for " "this %s object within the current thread; " "the %r attribute is unavailable." % (context, attr)) else: result = getter(transaction_context) if result is None: raise exception.ContextNotRequestedError( "The '%s' context attribute was requested but " "it has not been established for this context." % attr) return result