pycrdt icon indicating copy to clipboard operation
pycrdt copied to clipboard

Discarding origin is brittle

Open fcollonval opened this issue 10 months ago • 2 comments

I find the cleaning of the origin too brittle:

https://github.com/jupyter-server/pycrdt/blob/181c192f61ca6002a386d5449239e60523e30c0f/python/pycrdt/_transaction.py#L80

Reasons:

  • You cannot be sure the transaction will be discarded at exit.
  • The hashed_origin obtained is not the one stored in the __init__, how could you be sure you are not removing a reference to another hash?
  • The resource clearing is not happening in the mirror action of its creation; aka init <=> del

fcollonval avatar Feb 17 '25 17:02 fcollonval

  • The hashed_origin obtained is not the one stored in the __init__, how could you be sure you are not removing a reference to another hash?

You mean the hashed origin obtained in __exit__? If so, yes it is the one stored in __enter__, previously computed and registered in __init__. Am I missing something?

  • The resource clearing is not happening in the mirror action of its creation; aka init <=> del

A transaction should only be used with a context manager, so registering an origin in __init__ is equivalent to registering it in __enter__, which is symmetrical to the clearing happening in __exit__. But I agree that users could create the Transaction object and never use it in a context manager, for whatever reason. Moving the registering to __enter__ should handle that case, right? I guess that's also what you meant by:

  • You cannot be sure the transaction will be discarded at exit.

davidbrochart avatar Feb 17 '25 22:02 davidbrochart

In adding the transaction to event - I needed to revisit that part. See #233 for a proposal.

fcollonval avatar Feb 19 '25 15:02 fcollonval

Closing as no feedback, feel free to reopen.

davidbrochart avatar Jun 16 '25 06:06 davidbrochart