fix(cache): avoid treating class-like __array__ refs as data primitives#9569
Merged
mscolnick merged 3 commits intoMay 18, 2026
Merged
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Contributor
|
All contributors have signed the CLA ✍️ ✅ |
Contributor
There was a problem hiding this comment.
No issues found across 2 files
Architecture diagram
sequenceDiagram
participant Cache as Cache System
participant Primitive as is_data_primitive()
participant Inspect as inspect module
participant Array as __array__ Protocol
Note over Cache,Array: Data Primitive Classification Flow
Cache->>Primitive: Check if value is data primitive
Primitive->>Primitive: Check if value is basic primitive (int, str, etc.)
alt Value is basic primitive
Primitive-->>Cache: True (early return)
else Value is not basic primitive
Primitive->>Inspect: Check if value is a class
alt Value is a class
Primitive-->>Cache: False (reject class-like types)
else Value is not a class
Primitive->>Array: Check for __array__ protocol
alt Has __array__ and not class
Primitive->>Primitive: Route to data_to_buffer().view("uint8")
alt Array contains references/objects
Primitive-->>Cache: TypeError (cannot change dtype)
else Array contains primitive types
Primitive-->>Cache: Success
end
else No __array__ protocol
Primitive-->>Cache: False
end
end
end
Note over Cache,Inspect: Key Guard: inspect.isclass(value) prevents<br/>class-like __array__ references from entering buffer path
Author
|
I have read the CLA Document and I hereby sign the CLA |
dmadisetti
approved these changes
May 18, 2026
dmadisetti
left a comment
Member
There was a problem hiding this comment.
Thank you! Nice catch! The test also looks great
Contributor
|
🚀 Development release published. You may be able to view the changes at https://marimo.app?v=0.23.7-dev35 |
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
Closes #9563
This PR fixes a cache-classification edge case in
is_data_primitive:__array__were treated as data primitives.data_to_buffer(...).view("uint8"), which can fail for reference/object arrays with:TypeError: Cannot change data-type for array of references.inspect.isclass(value) -> False) inis_data_primitive.tests/_runtime/test_primitives.pyto assert class-like__array__refs are not classified as data primitives (issue persistent_cache: class-like __array__ refs can be misclassified as data primitives and crash hash serialization #9563 case).Validation run:
uv run --group test pytest tests/_runtime/test_primitives.py -k class_like_array_protocol→ passeduv run --group test pytest tests -k primitives→6 passed, 14 skipped, 8812 deselecteduv run --group test pytest tests -k cache→202 passed, 40 skipped, 8590 deselectedSkips are expected in this environment due to optional dependencies and version/platform-gated tests.
📋 Pre-Review Checklist
✅ Merge Checklist