A reactive notebook for Python — run reproducible experiments, query with SQL, execute as a script, deploy as an app, and version with git. Stored as pure Python. All in a modern, AI-native editor.
Python artificial-intelligencedagdata-sciencedata-visualizationdataflowdeveloper-toolsmachine-learningnotebookspipelinepythonreactivesqlweb-app
fix: do not double encode msgspec values (#9005)
Dylan Madisetti0731654f9d35
diff --git a/marimo/_messaging/notification.py b/marimo/_messaging/notification.pyindex f12bb881ec..64d98e52d5 100644--- a/marimo/_messaging/notification.py+++ b/marimo/_messaging/notification.py@@ -224,11 +224,13 @@ class ModelLifecycleNotification(Notification, tag="model-lifecycle"):import base64d: dict[str, Any] = msgspec.to_builtins(self)- # bytes are not JSON-serializable; base64-encode each buffermsg = d.get("message", {})if "buffers" in msg:msg["buffers"] = [- base64.b64encode(b).decode("ascii") for b in msg["buffers"]+ b+ if isinstance(b, str)+ else base64.b64encode(b).decode("ascii")+ for b in msg["buffers"]]return ddiff --git a/tests/_messaging/test_notifications.py b/tests/_messaging/test_notifications.pyindex 2df14b9ad3..18b7d12ab1 100644--- a/tests/_messaging/test_notifications.py+++ b/tests/_messaging/test_notifications.py@@ -7,6 +7,8 @@ from marimo._ast.toplevel import HINT_UNPARSABLE, TopLevelStatusfrom marimo._messaging.notification import (CellNotification,InstallingPackageAlertNotification,+ ModelLifecycleNotification,+ ModelOpen,StartupLogsNotification,UIElementMessageNotification,)@@ -137,3 +139,18 @@ def test_send_ui_element_message_broadcast() -> None:}assert stream.parsed_operations[0] == msg+++def test_model_lifecycle_notification_to_json_serializable() -> None:+ """to_json_serializable must not double-encode buffers (regression test)."""+ notif = ModelLifecycleNotification(+ model_id="model-1",+ message=ModelOpen(+ state={"value": 42},+ buffer_paths=[["data"]],+ buffers=[b"hello"],+ ),+ )++ result = notif.to_json_serializable()+ assert result["message"]["buffers"] == ["aGVsbG8="]