Merge "Support context function argument as keyword"
This commit is contained in:
commit
b9c51e295b
@ -1003,10 +1003,13 @@ class _TransactionContextManager(object):
|
||||
context_index = 1
|
||||
else:
|
||||
context_index = 0
|
||||
context_kw = argspec.args[context_index]
|
||||
|
||||
@functools.wraps(fn)
|
||||
def wrapper(*args, **kwargs):
|
||||
context = args[context_index]
|
||||
context = kwargs.get(context_kw, None)
|
||||
if not context:
|
||||
context = args[context_index]
|
||||
|
||||
with self._transaction_scope(context):
|
||||
return fn(*args, **kwargs)
|
||||
|
@ -519,6 +519,19 @@ class MockFacadeTest(oslo_test_base.BaseTestCase):
|
||||
with self._assert_reader_session(makers) as session:
|
||||
session.execute("test")
|
||||
|
||||
def test_session_reader_decorator_kwarg_call(self):
|
||||
context = oslo_context.RequestContext()
|
||||
|
||||
@enginefacade.reader
|
||||
def go(context):
|
||||
context.session.execute("test")
|
||||
go(context=context)
|
||||
|
||||
with self._assert_engines() as engines:
|
||||
with self._assert_makers(engines) as makers:
|
||||
with self._assert_reader_session(makers) as session:
|
||||
session.execute("test")
|
||||
|
||||
def test_connection_reader_decorator(self):
|
||||
context = oslo_context.RequestContext()
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user