Skip to content

Commit 37dd0ab

Browse files
authored
Merge pull request #84 from gmacon/transaction-aql
Honor read and write params in begin_transaction
2 parents 51b0060 + 63813bd commit 37dd0ab

File tree

2 files changed

+57
-0
lines changed

2 files changed

+57
-0
lines changed

arango/executor.py

+9
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

+48
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,54 @@ 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(
85+
return_result=True, read=[col.name], write=[col.name]) as txn_db:
86+
job1 = txn_db.aql.execute(
87+
'INSERT @data IN @@collection',
88+
bind_vars={'data': docs[0], '@collection': col.name})
89+
job2 = txn_db.aql.execute(
90+
'INSERT @data IN @@collection',
91+
bind_vars={'data': docs[1], '@collection': col.name})
92+
job3 = txn_db.aql.execute(
93+
'RETURN DOCUMENT(@@collection, @key)',
94+
bind_vars={'key': docs[1]['_key'], '@collection': col.name})
95+
jobs = txn_db.queued_jobs()
96+
assert jobs == [job1, job2, job3]
97+
assert all(job.status() == 'pending' for job in jobs)
98+
99+
assert txn_db.queued_jobs() == [job1, job2, job3]
100+
assert all(job.status() == 'done' for job in txn_db.queued_jobs())
101+
assert extract('_key', col.all()) == extract('_key', docs[:2])
102+
103+
# Test successful results
104+
assert extract('_key', job3.result()) == [docs[1]['_key']]
105+
106+
107+
def test_transaction_execute_aql_string_form(db, col, docs):
108+
with db.begin_transaction(
109+
return_result=True, read=col.name, write=col.name) as txn_db:
110+
job1 = txn_db.aql.execute(
111+
'INSERT @data IN @@collection',
112+
bind_vars={'data': docs[0], '@collection': col.name})
113+
job2 = txn_db.aql.execute(
114+
'INSERT @data IN @@collection',
115+
bind_vars={'data': docs[1], '@collection': col.name})
116+
job3 = txn_db.aql.execute(
117+
'RETURN DOCUMENT(@@collection, @key)',
118+
bind_vars={'key': docs[1]['_key'], '@collection': col.name})
119+
jobs = txn_db.queued_jobs()
120+
assert jobs == [job1, job2, job3]
121+
assert all(job.status() == 'pending' for job in jobs)
122+
123+
assert txn_db.queued_jobs() == [job1, job2, job3]
124+
assert all(job.status() == 'done' for job in txn_db.queued_jobs())
125+
assert extract('_key', col.all()) == extract('_key', docs[:2])
126+
127+
# Test successful results
128+
assert extract('_key', job3.result()) == [docs[1]['_key']]
129+
130+
83131
def test_transaction_execute_error_in_result(db, col, docs):
84132
txn_db = db.begin_transaction(timeout=100, sync=True)
85133
txn_col = txn_db.collection(col.name)

0 commit comments

Comments
 (0)