Skip to content

Commit

Permalink
Fix ReadTransaction (#48)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidbrochart authored Dec 14, 2023
1 parent ab2535a commit b687489
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
4 changes: 4 additions & 0 deletions python/pycrdt/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,11 @@ def observe_callback(callback: Callable[[Any], None], doc: Doc, event: Any):
def observe_deep_callback(callback: Callable[[Any], None], doc: Doc, events: list[Any]):
for idx, event in enumerate(events):
events[idx] = event_types[type(event)](event, doc)
if idx == 0:
_event = event
doc._txn = ReadTransaction(doc=doc, _txn=_event.transaction)
callback(events)
doc._txn = None


class ArrayEvent(BaseEvent):
Expand Down
4 changes: 4 additions & 0 deletions python/pycrdt/map.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,11 @@ def observe_callback(callback: Callable[[Any], None], doc: Doc, event: Any):
def observe_deep_callback(callback: Callable[[Any], None], doc: Doc, events: list[Any]):
for idx, event in enumerate(events):
events[idx] = event_types[type(event)](event, doc)
if idx == 0:
_event = event
doc._txn = ReadTransaction(doc=doc, _txn=_event.transaction)
callback(events)
doc._txn = None


class MapEvent(BaseEvent):
Expand Down
2 changes: 1 addition & 1 deletion python/pycrdt/transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def __exit__(
self._nb -= 1
# only drop the transaction when exiting root context manager
# since nested transactions reuse the root transaction
if self._nb == 0:
if self._nb == 0 and not isinstance(self, ReadTransaction):
# dropping the transaction will commit, no need to do it
# self._txn.commit()
assert self._txn is not None
Expand Down

0 comments on commit b687489

Please sign in to comment.