Discarding origin is brittle
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
- 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.
In adding the transaction to event - I needed to revisit that part. See #233 for a proposal.
Closing as no feedback, feel free to reopen.