diff --git a/arango/api.py b/arango/api.py index 46d8ed32..251de2e3 100644 --- a/arango/api.py +++ b/arango/api.py @@ -35,7 +35,7 @@ def __init__(self, protocol="http", host="localhost", port=8529, self.password = password self.db_name = db_name # self.client = SessionArangoClient() if client is None else client - self.client = DefaultArangoClient() if client is None else client + self.client = SessionArangoClient() if client is None else client @property def url_prefix(self): diff --git a/arango/database.py b/arango/database.py index ae005291..02256ed1 100644 --- a/arango/database.py +++ b/arango/database.py @@ -404,10 +404,9 @@ def remove_aql_function(self, name, group=None): # Transactions # ################ - # TODO deal with optional attribute "params" def execute_transaction(self, action, read_collections=None, - write_collections=None, wait_for_sync=False, - lock_timeout=None): + write_collections=None, params=None, + wait_for_sync=False, lock_timeout=None): """Execute the transaction and return the result. Setting the ``lock_timeout`` to 0 will make ArangoDB not time out @@ -419,6 +418,8 @@ def execute_transaction(self, action, read_collections=None, :type read_collections: str or list or None :param write_collections: the collections written to :type write_collections: str or list or None + :param params: Parameters for the function in action + :type params: list or dict or None :param wait_for_sync: wait for the transaction to sync to disk :type wait_for_sync: bool :param lock_timeout: timeout for waiting on collection locks @@ -433,11 +434,13 @@ def execute_transaction(self, action, read_collections=None, data["collections"]["read"] = read_collections if write_collections is not None: data["collections"]["write"] = write_collections - params = { + if params is not None: + data["params"] = params + http_params = { "waitForSync": wait_for_sync, "lockTimeout": lock_timeout, } - res = self._api.post(path=path, data=data, params=params) + res = self._api.post(path=path, data=data, params=http_params) if res.status_code != 200: raise TransactionExecuteError(res) return res.obj["result"] diff --git a/arango/tests/test_transaction.py b/arango/tests/test_transaction.py index 70c0c407..c132a24e 100644 --- a/arango/tests/test_transaction.py +++ b/arango/tests/test_transaction.py @@ -44,5 +44,33 @@ def test_execute_transaction(self): self.assertIn("doc02", self.col02) + def test_execute_transaction_params(self): + action = """ + function (params) { + var db = require('internal').db; + db.%s.save({ _key: 'doc11', val: params.val1 }); + db.%s.save({ _key: 'doc12', val: params.val2 }); + return 'success!'; + } + """ % (self.col_name01, self.col_name02) + + params = {"val1": 1, "val2": 2} + + res = self.db.execute_transaction( + action=action, + read_collections=[self.col_name01, self.col_name02], + write_collections=[self.col_name01, self.col_name02], + params=params, + wait_for_sync=True, + lock_timeout=10000 + ) + + self.assertEqual(res, "success!") + self.assertIn("doc11", self.col01) + self.assertIn("doc12", self.col02) + self.assertEqual(self.col01["doc11"]["val"], params["val1"]) + self.assertEqual(self.col02["doc12"]["val"], params["val2"]) + + if __name__ == "__main__": unittest.main() diff --git a/setup.py b/setup.py index 84b4e372..3d836fc5 100644 --- a/setup.py +++ b/setup.py @@ -7,7 +7,7 @@ setup( name="py-arango", description="Python Driver for ArangoDB", - version="1.3.0", + version="1.4.0", author="Joohwan Oh", author_email="joowani88@gmail.com", url="https://github.com/Joowani/py-arango",