pycrdt icon indicating copy to clipboard operation
pycrdt copied to clipboard

Missing transaction in Python event

Open fcollonval opened this issue 10 months ago • 1 comments

Description

The API of Yjs for event lists an attribute transaction to events. That attribute is defined in Rust but not accessible in Python as not listed in the slots.

Reproduce

In [1]: from pycrdt import Array, Doc, Map, Text

In [2]:     text = Text()
   ...:     array = Array()
   ...:     map_ = Map()
   ...:     Doc(
   ...:         {
   ...:             "text": text,
   ...:             "array": array,
   ...:             "map": map_,
   ...:         }
   ...:     )
   ...:     events = []

In [3]: def callback(event):
   ...:     print(event)
   ...:     print(event.transaction)

In [4]:     sub0 = text.observe(callback)  # noqa: F841
   ...:     sub1 = array.observe(callback)  # noqa: F841
   ...:     sub2 = map_.observe(callback)  # noqa: F841
   ...:     with text.doc.transaction():
   ...:         text += "hello"
   ...:         text += " world"
   ...:     array.append(1)
   ...:     map_["foo"] = "bar"

This will failed.

Expected behavior

No failure

Context

Version 0.10.9

fcollonval avatar Feb 17 '25 14:02 fcollonval

I wouldn't label it as a bug but as a feature request. Would you like to open a PR?

davidbrochart avatar Feb 17 '25 14:02 davidbrochart