10000 Integrate latest 3.12.1 changes by apetenchea · Pull Request #347 · arangodb/python-arango · GitHub
[go: up one dir, main page]

Skip to content

Integrate latest 3.12.1 changes #347

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 6 commits into from
Aug 7, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

10000
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Adding option skipFastLockRound for transactions
  • Loading branch information
apetenchea committed Aug 4, 2024
commit 22e6ea95c82d1fd93befcbed8c6e48c935bcbd54
9 changes: 9 additions & 0 deletions arango/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -3020,6 +3020,7 @@ def begin_transaction(
allow_implicit: Optional[bool] = None,
lock_timeout: Optional[int] = None,
max_size: Optional[int] = None,
skip_fast_lock_round: Optional[bool] = None,
) -> "TransactionDatabase":
"""Begin a transaction.

Expand All @@ -3043,6 +3044,9 @@ def begin_transaction(
:type lock_timeout: int | None
:param max_size: Max transaction size in bytes.
:type max_size: int | None
:param skip_fast_lock_round: Whether to disable fast locking for write
operations.
:type skip_fast_lock_round: bool | None
:return: Database API wrapper object specifically for transactions.
:rtype: arango.database.TransactionDatabase
"""
Expand All @@ -3055,6 +3059,7 @@ def begin_transaction(
allow_implicit=allow_implicit,
lock_timeout=lock_timeout,
max_size=max_size,
skip_fast_lock_round=skip_fast_lock_round,
)

def begin_controlled_execution(
Expand Down Expand Up @@ -3191,6 +3196,8 @@ class TransactionDatabase(Database):
:param transaction_id: Initialize using an existing transaction instead of creating
a new transaction.
:type transaction_id: str | None
:param skip_fast_lock_round: Whether to disable fast locking for write operations.
:type skip_fast_lock_round: bool | None
"""

def __init__(
Expand All @@ -3204,6 +3211,7 @@ def __init__(
lock_timeout: Optional[int] = None,
max_size: Optional[int] = None,
transaction_id: Optional[str] = None,
skip_fast_lock_round: Optional[bool] = False,
) -> None:
self._executor: TransactionApiExecutor
super().__init__(
Expand All @@ -3218,6 +3226,7 @@ def __init__(
lock_timeout=lock_timeout,
max_size=max_size,
transaction_id=transaction_id,
skip_fast_lock_round=skip_fast_lock_round,
),
)

Expand Down
5 changes: 5 additions & 0 deletions arango/executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,8 @@ class TransactionApiExecutor:
:param transaction_id: Initialize using an existing transaction instead of starting
a new transaction.
:type transaction_id: str | None
:param skip_fast_lock_round: Whether to disable fast locking for write operations.
:type skip_fast_lock_round: bool | None
"""

def __init__(
Expand All @@ -259,6 +261,7 @@ def __init__(
max_size: Optional[int] = None,
allow_dirty_read: bool = False,
transaction_id: Optional[str] = None,
skip_fast_lock_round: Optional[bool] = False,
) -> None:
self._conn = connection

Expand All @@ -279,6 +282,8 @@ def __init__(
data["lockTimeout"] = lock_timeout
if max_size is not None:
data["maxTransactionSize"] = max_size
if skip_fast_lock_round is not None:
data["skipFastLockRound"] = skip_fast_lock_round

if transaction_id is None:
request = Request(
Expand Down
26 changes: 22 additions & 4 deletions tests/test_transaction.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import pytest
from packaging import version

from arango.database import TransactionDatabase
from arango.exceptions import (
Expand All @@ -16,14 +17,15 @@ def test_transaction_execute_raw(db, col, docs):
# Test execute raw transaction
doc = docs[0]
key = doc["_key"]
result = db.execute_transaction(
command=f"""
command = f"""
function (params) {{
var db = require('internal').db;
db.{col.name}.save({{'_key': params.key, 'val': 1}});
return true;
}}
""",
""" # noqa: E702 E231 E272 E202
result = db.execute_transaction(
command=command,
params={"key": key},
write=[col.name],
read=[col.name],
Expand All @@ -43,7 +45,7 @@ def test_transaction_execute_raw(db, col, docs):
assert err.value.error_code == 10


def test_transaction_init(db, bad_db, col, username):
def test_transaction_init(db, db_version, bad_db, col, username):
txn_db = db.begin_transaction()

assert isinstance(txn_db, TransactionDatabase)
Expand All @@ -68,6 +70,22 @@ def test_transaction_init(db, bad_db, col, username):
bad_db.begin_transaction()
assert err.value.error_code in {11, 1228}

# Test all options
kwargs = dict(
read=col.name,
write=col.name,
exclusive=[],
sync=True,
allow_implicit=False,
lock_timeout=1000,
max_size=1024 * 1024,
)
if db_version >= version.parse("3.12.1"):
kwargs["skip_fast_lock_round"] = True
txn_db = db.begin_transaction(**kwargs)
assert isinstance(txn_db, TransactionDatabase)
assert txn_db.transaction_id is not None


def test_transaction_status(db, col, docs):
txn_db = db.begin_transaction(read=col.name)
Expand Down
0