-
Notifications
You must be signed in to change notification settings - Fork 16
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
Shared Types Popped from Shared Map are Empty #94
Shared Types Popped from Shared Map are Empty #94
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for investigating @jbdyn!
I think pop
should not return a shared type, but instead the pure Python object. This means that pop
can have a different return value than get
, but I think this is fine.
Would you mind doing the same changes for Array.pop
?
❤️
Sure, I can do that. |
Thanks @jbdyn ! |
Released in v0.8.18. |
Hi 👋
I experienced that, when having a shared datatype nested into a shared map, and popping that nested item, the returned item is of the same shared datatype, but empty:
This is also the same for nested Shared Arrays and Shared Text, but not for Subdocs.
After some hours, I found the deletion to happen here
pycrdt/python/pycrdt/_map.py
Lines 110 to 111 in 15a47b0
where
res
is the popped shared type and populated (as expected), but empty after callingdel self[key]
.According to the Yrs docs, this is expected behavior for Shared Maps:
So, we need to copy the content to another object before perfoming the removal with
del self[key]
.I quickly added tests as well as a check if
res
is an instance ofBaseType
, relying on the methodto_py
to be defined, but maybe a more sophisticated fix with__copy__
and__deepcopy__
implemented might be better?