fix(registry): pass element id to delete() on re-register, not weakref wrapper id#9640
Open
xodn348 wants to merge 1 commit into
Open
fix(registry): pass element id to delete() on re-register, not weakref wrapper id#9640xodn348 wants to merge 1 commit into
xodn348 wants to merge 1 commit into
Conversation
…ister
In UIElementRegistry.register(), when an object_id is already known, the
old element is deleted via:
self.delete(object_id, id(self._objects[object_id]))
self._objects[object_id] is a weakref.ref wrapper, so id() here yields the
wrapper's address — not the element's. In delete(), the guard compares that
python_id against id(element) (dereferenced). They never match, so delete()
always returns early without calling ctx.function_registry.delete().
Fix: dereference the weakref first:
self.delete(object_id, id(self._objects[object_id]()))
If the referent has already been GC'd (returns None), id(None) is passed;
delete()'s guard sets registered_python_id=None and the element is still
removed correctly.
Fixes marimo-team#9551
Author
|
I have read the CLA Document and I hereby sign the CLA |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
I have read the CLA Document and I hereby sign the CLA You can retrigger this bot by commenting recheck in this Pull Request. Posted by the CLA Assistant Lite bot. |
Contributor
Contributor
|
i do think #9551 is a different issue completely |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes a bug in
UIElementRegistry.register()wheredelete()was called with the Python id of theweakref.refwrapper rather than the id of the wrappedUIElement. Becausedelete()derivesregistered_python_idby dereferencing the weakref and callingid()on the result, the two ids never match, sodelete()always returns early — skipping thectx.function_registry.delete(namespace=object_id)call that is supposed to clean up function-registry entries for the old element on cell re-run.The fix is a single-character change:
id(self._objects[object_id])→id(self._objects[object_id]()).Closes #9551
📝 Summary
Fixes a bug in
UIElementRegistry.register()wheredelete()was called with the Python id of theweakref.refwrapper rather than the id of the wrappedUIElement. Becausedelete()derivesregistered_python_idby dereferencing the weakref and callingid()on the result, the two ids never match, sodelete()always returns early — skipping thectx.function_registry.delete(namespace=object_id)call that is supposed to clean up function-registry entries for the old element when a cell is re-run with the same UI element id.The fix is a one-character change: dereference the weakref before calling
id():📋 Pre-Review Checklist
✅ Merge Checklist
Local verification
Risk
The changed line is inside the
if object_id in self._objects:branch ofregister(), which only fires on cell re-run where the same UI element id is re-registered. The existingtest_dont_delete_element_with_wrong_python_idtest (which deliberately passespython_id=-1) is unaffected. No public API is changed.