Skip to content

Support __buffer__ objects in widget comm buffers#8283

Merged
mscolnick merged 2 commits intomainfrom
push-qqukomlnnknw
Feb 13, 2026
Merged

Support __buffer__ objects in widget comm buffers#8283
mscolnick merged 2 commits intomainfrom
push-qqukomlnnknw

Conversation

@manzt
Copy link
Collaborator

@manzt manzt commented Feb 12, 2026

Libraries like obstore expose a Bytes type that implements Python's buffer protocol but isn't a subclass of bytes, memoryview, or bytearray. When these objects ended up in widget comm buffers (e.g. from lonboard map tiles), msgspec didn't recognise them as native binary types and fell through to enc_hook, which produced invalid output instead of base64.

This adds _ensure_bytes() in the comm layer to coerce any buffer-protocol object to plain bytes before building model messages.

Needed to support raster tiles in lonboard:

@vercel
Copy link

vercel bot commented Feb 12, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
marimo-docs Ready Ready Preview, Comment Feb 12, 2026 10:47pm

Request Review

@manzt manzt added the enhancement New feature or request label Feb 12, 2026
@manzt manzt changed the title Support buffer protocol objects in widget comm buffers Support __buffer__ objects in widget comm buffers Feb 12, 2026
mscolnick
mscolnick previously approved these changes Feb 12, 2026
DataType = Optional[dict[str, Any]]
MetadataType = Optional[dict[str, Any]]
BufferType = Optional[list[bytes]]
Buffer = bytes | memoryview | bytearray

Choose a reason for hiding this comment

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



def _ensure_bytes(buf: object) -> bytes:
"""Coerce a buffer to plain ``bytes`` for msgspec serialization.

Choose a reason for hiding this comment

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

Seems like that's the core issue, right? msgspec should handle buffers

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah exactly, we need upstream support but need some compatibility now.

Libraries like obstore expose a `Bytes` type that implements Python's
buffer protocol but isn't a subclass of `bytes`, `memoryview`, or
`bytearray`. When these objects ended up in widget comm buffers (e.g.
from lonboard map tiles), msgspec didn't recognise them as native binary
types and fell through to `enc_hook`, which produced invalid output
instead of base64.

This adds `_ensure_bytes()` in the comm layer to coerce any
buffer-protocol object to plain `bytes` before building model messages.
@mscolnick mscolnick merged commit 36381ea into main Feb 13, 2026
42 of 43 checks passed
@mscolnick mscolnick deleted the push-qqukomlnnknw branch February 13, 2026 17:15
LiquidGunay pushed a commit to LiquidGunay/marimo that referenced this pull request Feb 21, 2026
Libraries like obstore expose a `Bytes` type that implements Python's
buffer protocol but isn't a subclass of `bytes`, `memoryview`, or
`bytearray`. When these objects ended up in widget comm buffers (e.g.
from lonboard map tiles), msgspec didn't recognise them as native binary
types and fell through to `enc_hook`, which produced invalid output
instead of base64.

This adds `_ensure_bytes()` in the comm layer to coerce any
buffer-protocol object to plain `bytes` before building model messages.


Needed to support raster tiles in `lonboard`: 
<img
src="https://github.com/user-attachments/assets/0652f406-779d-4db5-bca9-03dd315301a7"
/>
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.

3 participants