Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add transaction to event slots #233

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

fcollonval
Copy link
Member

@fcollonval fcollonval commented Feb 17, 2025

Fixes #232
Fixes #234

Add transaction to event slots.

This ends up a bit more complex to be able to keep a reference to the transaction in the event, this PR introduced a BaseTransaction that only keeps reference to the document and the origin (independently of the rust object).
That ensures the introspection of the event at any time.

It also introduces a more robust way to maintain the mapping of Python origin and rust origin.

@fcollonval fcollonval added the enhancement New feature or request label Feb 17, 2025
fcollonval and others added 4 commits February 19, 2025 11:50
More robust handling of mapping between origin and its hashed value
@davidbrochart
Copy link
Collaborator

Thanks for the PR, I will have a look soon.

Comment on lines +37 to +38
if getattr(self, "_origin_hash", None) is not None:
self._doc._origins.remove(cast(int, self._origin_hash))
Copy link
Collaborator

@davidbrochart davidbrochart Feb 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why using getattr, since _origin_hash is set in __init__?

@property
def origin(self) -> Any:
"""The origin of the transaction."""
return self._doc._origins.get(self._origin_hash) if self._origin_hash else None
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not very likely, but since a hash is an int it could be 0.

Suggested change
return self._doc._origins.get(self._origin_hash) if self._origin_hash else None
return None if self._origin_hash is None else self._doc._origins.get(self._origin_hash)

Comment on lines -78 to -80
origin_hash = self._txn.origin()
if origin_hash is not None:
del self._doc._origins[origin_hash]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That was a very deterministic behavior, why did you move that part to the transaction's __del__ method?

@davidbrochart
Copy link
Collaborator

@fcollonval Could you explain the reasoning about adding a reference count to origins?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Discarding origin is brittle Missing transaction in Python event
2 participants