Skip to content

Commit ac96017

Browse files
committed
✨ [feat][backend] support for_update param on read txn crud func
1 parent eb3110a commit ac96017

2 files changed

Lines changed: 14 additions & 0 deletions

File tree

backend/kayman/crud/transaction.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ def read_transactions(
3434
event_id: int | Literal["empty"] | None = None,
3535
order_by: TransactionOrderBy | None = None,
3636
descending: bool = False,
37+
for_update: bool = False,
3738
) -> Sequence[Transaction]:
3839
scalar = select(Transaction)
3940
if transaction_id is not None:
@@ -51,5 +52,7 @@ def read_transactions(
5152
if order_by is not None:
5253
column = getattr(Transaction, order_by)
5354
scalar = scalar.order_by(column.desc() if descending else column.asc())
55+
if for_update:
56+
scalar = scalar.with_for_update()
5457
txns = session.exec(scalar).all()
5558
return txns

backend/kayman/tests/crud/test_transaction.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from datetime import UTC, datetime
22
from decimal import Decimal
3+
from unittest.mock import patch
34

45
from sqlmodel import Session
56

@@ -253,3 +254,13 @@ def test_read_transactions_descending_without_order_by_is_unsorted(session: Sess
253254
results = read_transactions(session, account_id=account.id, descending=True)
254255

255256
assert len(results) == 3
257+
258+
259+
def test_read_transactions_for_update(session: Session):
260+
TransactionFactory()
261+
262+
with patch.object(session, "exec", wraps=session.exec) as mock_exec:
263+
read_transactions(session, for_update=True)
264+
args = mock_exec.call_args[0]
265+
statement = str(args[0])
266+
assert "FOR UPDATE" in statement

0 commit comments

Comments
 (0)