mirror of
https://github.com/apple/foundationdb.git
synced 2025-05-14 09:58:50 +08:00
Ban generators in 7.0.0
This commit is contained in:
parent
62baf6d121
commit
4ceae8c83a
@ -252,6 +252,12 @@ def transactional(*tr_args, **tr_kwargs):
|
||||
else:
|
||||
@functools.wraps(func)
|
||||
def wrapper(*args, **kwargs):
|
||||
# We can't throw this from the decorator, as when a user runs
|
||||
# >>> import fdb ; fdb.api_version(700)
|
||||
# the code above uses @transactional before the API version is set
|
||||
if fdb.get_api_version() >= 700 and inspect.isgeneratorfunction(func):
|
||||
raise ValueError("Generators can not be wrapped with fdb.transactional")
|
||||
|
||||
if isinstance(args[index], TransactionRead):
|
||||
return func(*args, **kwargs)
|
||||
|
||||
@ -267,14 +273,13 @@ def transactional(*tr_args, **tr_kwargs):
|
||||
ret = None
|
||||
try:
|
||||
ret = func(*largs, **kwargs)
|
||||
if fdb.get_api_version() >= 700 and inspect.isgenerator(ret):
|
||||
raise ValueError("Generators can not be wrapped with fdb.transactional")
|
||||
tr.commit().wait()
|
||||
committed = True
|
||||
except FDBError as e:
|
||||
tr.on_error(e.code).wait()
|
||||
|
||||
if fdb.get_api_version() >= 620 and isinstance(ret, types.GeneratorType):
|
||||
raise ValueError("Generators can not be wrapped with fdb.transactional")
|
||||
|
||||
# now = datetime.datetime.now()
|
||||
# td = now - last
|
||||
# elapsed = (td.microseconds + (td.seconds + td.days * 24 * 3600) * 10**6) / float(10**6)
|
||||
|
@ -132,10 +132,22 @@ def test_fdb_transactional_generator(db):
|
||||
@fdb.transactional
|
||||
def function_that_yields(tr):
|
||||
yield 0
|
||||
function_that_yields(db)
|
||||
assert fdb.get_api_version() < 620, "Generators post-6.2.0 should throw"
|
||||
assert fdb.get_api_version() < 700, "Pre-7.0, a decorators may wrap a function that yield"
|
||||
except ValueError as e:
|
||||
pass
|
||||
assert fdb.get_api_version() >= 700, "Post-7.0, a decorator should throw if wrapped function yields"
|
||||
|
||||
|
||||
def test_fdb_transactional_returns_generator(db):
|
||||
try:
|
||||
def function_that_yields(tr):
|
||||
yield 0
|
||||
@fdb.transactional
|
||||
def function_that_returns(tr):
|
||||
return function_that_yields(tr)
|
||||
function_that_returns()
|
||||
assert fdb.get_api_version() < 700, "Pre-7.0, returning a generator is allowed"
|
||||
except ValueError as e:
|
||||
assert fdb.get_api_version() >= 700, "Post-7.0, returning a generator should throw"
|
||||
|
||||
|
||||
def test_db_options(db):
|
||||
|
Loading…
x
Reference in New Issue
Block a user