File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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
Original file line number Diff line number Diff line change 11from datetime import UTC , datetime
22from decimal import Decimal
3+ from unittest .mock import patch
34
45from 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
You can’t perform that action at this time.
0 commit comments