Skip to content

Commit 0bffcff

Browse files
committed
Honor read and write params to begin_transaction
1 parent 51b0060 commit 0bffcff

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

arango/executor.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,16 @@ def commit(self):
347347
return self.jobs
348348

349349
write_collections = set()
350+
if isinstance(self._write, string_types):
351+
write_collections.add(self._write)
352+
elif self._write is not None:
353+
write_collections |= set(self._write)
354+
350355
read_collections = set()
356+
if isinstance(self._read, string_types):
357+
read_collections.add(self._read)
358+
elif self._read is not None:
359+
read_collections |= set(self._read)
351360

352361
# Buffer for building the transaction javascript command
353362
cmd_buffer = [

tests/test_transaction.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,29 @@ def test_transaction_execute_with_result(db, col, docs):
8080
assert job3.result()['_key'] == docs[1]['_key']
8181

8282

83+
def test_transaction_execute_aql(db, col, docs):
84+
with db.begin_transaction(return_result=True, write=[col.name]) as txn_db:
85+
job1 = txn_db.aql.execute(
86+
'INSERT @data IN @@collection',
87+
bind_vars={'data': docs[0], '@collection': col.name})
88+
job2 = txn_db.aql.execute(
89+
'INSERT @data IN @@collection',
90+
bind_vars={'data': docs[1], '@collection': col.name})
91+
job3 = txn_db.aql.execute(
92+
'RETURN DOCUMENT(@@collection, @key)',
93+
bind_vars={'key': docs[1]['_key'], '@collection': col.name})
94+
jobs = txn_db.queued_jobs()
95+
assert jobs == [job1, job2, job3]
96+
assert all(job.status() == 'pending' for job in jobs)
97+
98+
assert txn_db.queued_jobs() == [job1, job2, job3]
99+
assert all(job.status() == 'done' for job in txn_db.queued_jobs())
100+
assert extract('_key', col.all()) == extract('_key', docs[:2])
101+
102+
# Test successful results
103+
assert extract('_key', job3.result()) == [docs[1]['_key']]
104+
105+
83106
def test_transaction_execute_error_in_result(db, col, docs):
84107
txn_db = db.begin_transaction(timeout=100, sync=True)
85108
txn_col = txn_db.collection(col.name)

0 commit comments

Comments
 (0)