Skip to content

Commit 02184bb

Browse files
committed
Fixes #257
1 parent 412b98e commit 02184bb

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

neo4j/__init__.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -652,15 +652,16 @@ def _run_transaction(self, access_mode, unit_of_work, *args, **kwargs):
652652
raise TypeError("Unit of work is not callable")
653653

654654
metadata = getattr(unit_of_work, "metadata", None)
655-
print(metadata) # TODO
655+
timeout = getattr(unit_of_work, "timeout", None)
656+
656657
retry_delay = retry_delay_generator(INITIAL_RETRY_DELAY,
657658
RETRY_DELAY_MULTIPLIER,
658659
RETRY_DELAY_JITTER_FACTOR)
659660
errors = []
660661
t0 = perf_counter()
661662
while True:
662663
try:
663-
self._open_transaction(access_mode)
664+
self._open_transaction(access_mode, metadata, timeout)
664665
tx = self._transaction
665666
try:
666667
result = unit_of_work(tx, *args, **kwargs)
@@ -1405,7 +1406,7 @@ def __init__(self, transaction, *args, **kwargs):
14051406
self.transaction = transaction
14061407

14071408

1408-
def unit_of_work(**metadata):
1409+
def unit_of_work(metadata=None, timeout=None):
14091410
""" Decorator for transaction functions.
14101411
"""
14111412

@@ -1415,6 +1416,7 @@ def wrapped(*args, **kwargs):
14151416
return f(*args, **kwargs)
14161417

14171418
wrapped.metadata = metadata
1419+
wrapped.timeout = timeout
14181420
return wrapped
14191421

14201422
return wrapper

test/integration/test_session.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -579,14 +579,16 @@ def work(tx, x):
579579
self.assertEqual(value, 1)
580580

581581
def test_read_with_arg_and_metadata(self):
582+
if self.protocol_version() < 3:
583+
raise SkipTest("Transaction metadata and timeout only supported in Bolt v3+")
582584

583585
@unit_of_work(timeout=25, metadata={"foo": "bar"})
584-
def work(tx, x):
585-
return tx.run("RETURN $x", x=x).single().value()
586+
def work(tx):
587+
return tx.run("CALL dbms.getTXMetaData").single().value()
586588

587589
with self.driver.session() as session:
588-
value = session.read_transaction(work, x=1)
589-
self.assertEqual(value, 1)
590+
value = session.read_transaction(work)
591+
self.assertEqual(value, {"foo": "bar"})
590592

591593
def test_simple_write(self):
592594

@@ -607,6 +609,8 @@ def work(tx, x):
607609
self.assertEqual(value, 1)
608610

609611
def test_write_with_arg_and_metadata(self):
612+
if self.protocol_version() < 3:
613+
raise SkipTest("Transaction metadata and timeout only supported in Bolt v3+")
610614

611615
@unit_of_work(timeout=25, metadata={"foo": "bar"})
612616
def work(tx, x):

0 commit comments

Comments
 (0)