Skip to content

Commit b687489

Browse files
Fix ReadTransaction (#48)
1 parent ab2535a commit b687489

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

python/pycrdt/array.py

+4
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,11 @@ def observe_callback(callback: Callable[[Any], None], doc: Doc, event: Any):
206206
def observe_deep_callback(callback: Callable[[Any], None], doc: Doc, events: list[Any]):
207207
for idx, event in enumerate(events):
208208
events[idx] = event_types[type(event)](event, doc)
209+
if idx == 0:
210+
_event = event
211+
doc._txn = ReadTransaction(doc=doc, _txn=_event.transaction)
209212
callback(events)
213+
doc._txn = None
210214

211215

212216
class ArrayEvent(BaseEvent):

python/pycrdt/map.py

+4
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,11 @@ def observe_callback(callback: Callable[[Any], None], doc: Doc, event: Any):
160160
def observe_deep_callback(callback: Callable[[Any], None], doc: Doc, events: list[Any]):
161161
for idx, event in enumerate(events):
162162
events[idx] = event_types[type(event)](event, doc)
163+
if idx == 0:
164+
_event = event
165+
doc._txn = ReadTransaction(doc=doc, _txn=_event.transaction)
163166
callback(events)
167+
doc._txn = None
164168

165169

166170
class MapEvent(BaseEvent):

python/pycrdt/transaction.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def __exit__(
3535
self._nb -= 1
3636
# only drop the transaction when exiting root context manager
3737
# since nested transactions reuse the root transaction
38-
if self._nb == 0:
38+
if self._nb == 0 and not isinstance(self, ReadTransaction):
3939
# dropping the transaction will commit, no need to do it
4040
# self._txn.commit()
4141
assert self._txn is not None

0 commit comments

Comments
 (0)