Skip to content

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.

fix: panel function parsing (#2722)

Myles Scolnick3db6df270575
diff --git a/frontend/src/plugins/impl/panel/PanelPlugin.tsx b/frontend/src/plugins/impl/panel/PanelPlugin.tsx
index 623f2c2e40..5da1368e3c 100644
--- a/frontend/src/plugins/impl/panel/PanelPlugin.tsx
+++ b/frontend/src/plugins/impl/panel/PanelPlugin.tsx
@@ -145,7 +145,7 @@ const PanelSlot = (props: Props) => {
return;
}
const message = MessageSchema.parse(e.detail.message);
- if (message.type === "ACK") {
+ if (message.content.type === "ACK") {
if (event_buffer.length > 0) {
process_events();
timeout = Date.now();
@@ -225,13 +225,6 @@ const PanelSlot = (props: Props) => {
);
};
-const MessageSchema = z.union([
- z.object({
- type: z.literal("ACK"),
- content: z.any(),
- }),
- z.object({
- type: z.string().optional(),
- content: z.any(),
- }),
-]);
+const MessageSchema = z.object({
+ content: z.any(),
+});
diff --git a/marimo/_plugins/ui/_impl/from_panel.py b/marimo/_plugins/ui/_impl/from_panel.py
index 8d06bd36e3..17432045cb 100644
--- a/marimo/_plugins/ui/_impl/from_panel.py
+++ b/marimo/_plugins/ui/_impl/from_panel.py
@@ -4,7 +4,7 @@ from __future__ import annotations
import sys
from dataclasses import dataclass
from functools import partial
-from typing import Any, Dict, Optional, Tuple
+from typing import Any, Dict, List, Optional, Tuple
from marimo import _loggers
from marimo._output.rich_help import mddoc
@@ -32,7 +32,7 @@ T = Dict[str, Any]
@dataclass
class SendToWidgetArgs:
message: Any
- buffers: Optional[Dict[int, Any]] = None
+ buffers: Optional[List[Any]] = None
def _get_comm_class() -> Any:
@@ -217,7 +217,7 @@ class panel(UIElement[T, T]):
),
)
- def _handle_msg(self, ref: str, msg: Any) -> None:
+ def _handle_msg(self, ref: str, msg: SendToWidgetArgs) -> None:
comm = self.obj._comms[ref][0]
msg = comm.decode(msg)
self.obj._on_msg(ref, self._manager, msg)
diff --git a/marimo/_runtime/functions.py b/marimo/_runtime/functions.py
index e98507e731..9113ab8606 100644
--- a/marimo/_runtime/functions.py
+++ b/marimo/_runtime/functions.py
@@ -7,8 +7,12 @@ import dataclasses
from typing import Any, Callable, Coroutine, Generic, Type, TypeVar
from marimo._ast.cell import CellId_t
+from marimo._loggers import marimo_logger
from marimo._utils.parse_dataclass import parse_raw
+LOGGER = marimo_logger()
+
+
S = TypeVar("S")
T = TypeVar("T")
@@ -53,7 +57,11 @@ class Function(Generic[S, T]):
self.cell_id = None
def __call__(self, args: dict[Any, Any]) -> T | Coroutine[Any, Any, T]:
- return self.function(parse_raw(args, self.arg_cls))
+ try:
+ return self.function(parse_raw(args, self.arg_cls))
+ except Exception as e:
+ LOGGER.error(f"Error calling function {self.name}: {e}")
+ raise e
@dataclasses.dataclass