Skip to content

Honor read and write params to begin_transaction #84

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions arango/executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,16 @@ def commit(self):
return self.jobs

write_collections = set()
if isinstance(self._write, string_types):
write_collections.add(self._write)
elif self._write is not None:
write_collections |= set(self._write)

read_collections = set()
if isinstance(self._read, string_types):
read_collections.add(self._read)
elif self._read is not None:
read_collections |= set(self._read)

# Buffer for building the transaction javascript command
cmd_buffer = [
Expand Down
48 changes: 48 additions & 0 deletions tests/test_transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,54 @@ def test_transaction_execute_with_result(db, col, docs):
assert job3.result()['_key'] == docs[1]['_key']


def test_transaction_execute_aql(db, col, docs):
with db.begin_transaction(
return_result=True, read=[col.name], write=[col.name]) as txn_db:
job1 = txn_db.aql.execute(
'INSERT @data IN @@collection',
bind_vars={'data': docs[0], '@collection': col.name})
job2 = txn_db.aql.execute(
'INSERT @data IN @@collection',
bind_vars={'data': docs[1], '@collection': col.name})
job3 = txn_db.aql.execute(
'RETURN DOCUMENT(@@collection, @key)',
bind_vars={'key': docs[1]['_key'], '@collection': col.name})
jobs = txn_db.queued_jobs()
assert jobs == [job1, job2, job3]
assert all(job.status() == 'pending' for job in jobs)

assert txn_db.queued_jobs() == [job1, job2, job3]
assert all(job.status() == 'done' for job in txn_db.queued_jobs())
assert extract('_key', col.all()) == extract('_key', docs[:2])

# Test successful results
assert extract('_key', job3.result()) == [docs[1]['_key']]


def test_transaction_execute_aql_string_form(db, col, docs):
with db.begin_transaction(
return_result=True, read=col.name, write=col.name) as txn_db:
job1 = txn_db.aql.execute(
'INSERT @data IN @@collection',
bind_vars={'data': docs[0], '@collection': col.name})
job2 = txn_db.aql.execute(
'INSERT @data IN @@collection',
bind_vars={'data': docs[1], '@collection': col.name})
job3 = txn_db.aql.execute(
'RETURN DOCUMENT(@@collection, @key)',
bind_vars={'key': docs[1]['_key'], '@collection': col.name})
jobs = txn_db.queued_jobs()
assert jobs == [job1, job2, job3]
assert all(job.status() == 'pending' for job in jobs)

assert txn_db.queued_jobs() == [job1, job2, job3]
assert all(job.status() == 'done' for job in txn_db.queued_jobs())
assert extract('_key', col.all()) == extract('_key', docs[:2])

# Test successful results
assert extract('_key', job3.result()) == [docs[1]['_key']]


def test_transaction_execute_error_in_result(db, col, docs):
txn_db = db.begin_transaction(timeout=100, sync=True)
txn_col = txn_db.collection(col.name)
Expand Down