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: harden validation and export error handling (#10420)
Myles Scolnickdaa5d6803377
diff --git a/marimo/_convert/converters.py b/marimo/_convert/converters.pyindex 564809273c..8c7c4ebeee 100644--- a/marimo/_convert/converters.py+++ b/marimo/_convert/converters.py@@ -1,6 +1,7 @@# Copyright 2026 Marimo. All rights reserved.from __future__ import annotations+from dataclasses import replacefrom typing import TYPE_CHECKINGfrom marimo._schemas.notebook import NotebookV1@@ -61,7 +62,10 @@ class MarimoConvert:"""from marimo._ast.parse import parse_notebook- ir = parse_notebook(source) or EMPTY_NOTEBOOK_SERIALIZATION+ ir = parse_notebook(source, filepath="notebook.py") or replace(+ EMPTY_NOTEBOOK_SERIALIZATION,+ filename="notebook.py",+ )return MarimoConverterIntermediate(ir)@staticmethoddiff --git a/marimo/_convert/markdown/flavor/__init__.py b/marimo/_convert/markdown/flavor/__init__.pyindex 861cfcab2e..632c2f9f76 100644--- a/marimo/_convert/markdown/flavor/__init__.py+++ b/marimo/_convert/markdown/flavor/__init__.py@@ -114,7 +114,12 @@ def _markdown_output_extension(flavor: MarkdownFlavor | MarkdownFlavorName,) -> str:flavor_name = flavor.name if isinstance(flavor, MarkdownFlavor) else flavor- return _MARKDOWN_OUTPUT_EXTENSIONS[flavor_name]+ try:+ return _MARKDOWN_OUTPUT_EXTENSIONS[flavor_name]+ except KeyError as error:+ raise ValueError(+ f"Unsupported markdown flavor: {flavor_name!r}"+ ) from errordef markdown_output_filename(diff --git a/marimo/_plugins/stateless/callout.py b/marimo/_plugins/stateless/callout.pyindex 2f4211d234..0b1ea0b6f7 100644--- a/marimo/_plugins/stateless/callout.py+++ b/marimo/_plugins/stateless/callout.py@@ -1,7 +1,7 @@# Copyright 2026 Marimo. All rights reserved.from __future__ import annotations-from typing import Literal+from typing import Literal, get_argsfrom marimo._output.formatting import as_htmlfrom marimo._output.hypertext import ContainerHtml@@ -12,6 +12,7 @@ from marimo._plugins.core.web_component import ()CalloutKind = Literal["neutral", "warn", "success", "info", "danger"]+CALLOUT_KINDS: tuple[CalloutKind, ...] = get_args(CalloutKind)@mddoc@@ -30,6 +31,11 @@ class callout(ContainerHtml):kind: CalloutKind = "neutral",title: str | None = None,) -> None:+ if kind not in CALLOUT_KINDS:+ raise ValueError(+ f"Unsupported callout kind: {kind!r}. "+ f"Expected one of {CALLOUT_KINDS}."+ )self._kind = kindself._title = titlesuper().__init__([as_html(value)])diff --git a/marimo/_sql/sql_quoting.py b/marimo/_sql/sql_quoting.pyindex b9d952d0bd..cf78dc0b77 100644--- a/marimo/_sql/sql_quoting.py+++ b/marimo/_sql/sql_quoting.py@@ -13,23 +13,20 @@ def quote_sql_identifier(identifier: str, *, dialect: str = "duckdb") -> str:dialect: The SQL dialect.Double-quote style: "duckdb", "redshift", "postgresql"/"postgres".Backtick style: "clickhouse", "mysql", "bigquery", "starrocks".- Unknown dialects return the identifier unquoted.+ Unknown dialects use ANSI double-quote style.Returns:The properly quoted identifier string."""- if dialect in ("duckdb", "redshift", "postgresql", "postgres"):- # Double-quote style: escape embedded " as ""- escaped = identifier.replace('"', '""')- return f'"{escaped}"'- elif dialect in ("clickhouse", "mysql", "bigquery", "starrocks"):+ if dialect in ("clickhouse", "mysql", "bigquery", "starrocks"):# Backtick style: escape embedded ` as ``escaped = identifier.replace("`", "``")return f"`{escaped}`"else:- # Unknown dialect: return unquoted to avoid breaking databases- # that treat quoted identifiers differently- return identifier+ # ANSI double-quote style: escape embedded " as "". Use this safe+ # default for unknown dialects instead of returning raw identifiers.+ escaped = identifier.replace('"', '""')+ return f'"{escaped}"'def quote_qualified_name(*parts: str, dialect: str = "duckdb") -> str:diff --git a/tests/_convert/markdown/test_markdown_from_ir.py b/tests/_convert/markdown/test_markdown_from_ir.pyindex 5e1219806b..894334929a 100644--- a/tests/_convert/markdown/test_markdown_from_ir.py+++ b/tests/_convert/markdown/test_markdown_from_ir.py@@ -414,6 +414,14 @@ def test_markdown_output_filename(filename, flavor, expected):assert markdown_output_filename(filename, flavor) == expected+def test_markdown_output_filename_rejects_unknown_flavor():+ with pytest.raises(+ ValueError,+ match="Unsupported markdown flavor: 'bogus'",+ ):+ markdown_output_filename("nb.md", "bogus") # type: ignore[arg-type]++@pytest.mark.parametrize(("filename", "flavor", "expected_head", "expected_name"),[diff --git a/tests/_convert/test_convert_py.py b/tests/_convert/test_convert_py.pyindex b8e62f1f63..eabb782edc 100644--- a/tests/_convert/test_convert_py.py+++ b/tests/_convert/test_convert_py.py@@ -6,6 +6,12 @@ from textwrap import dedentfrom marimo import __version__from marimo._convert.converters import MarimoConvertfrom marimo._convert.script import _header_for_script+from marimo._export.exporter import export_markdown, export_script+from marimo._export.requests import (+ MarkdownExportRequest,+ ScriptExportRequest,+)+from marimo._schemas.export_options import MarkdownExportOptionsfrom tests.mocks import snapshottersnapshot = snapshotter(__file__)@@ -64,6 +70,29 @@ def test_basic_marimo_example_jupytext_compatibility():snapshot("basic_marimo_example_roundtrip.py.txt", converted_back)+def test_from_py_ir_can_be_exported_without_filename_fixup() -> None:+ source = "import marimo\napp = marimo.App()\n"++ ir = MarimoConvert.from_py(source).to_ir()+ script = export_script(ScriptExportRequest(notebook=ir))+ markdown = export_markdown(+ MarkdownExportRequest(+ notebook=ir,+ options=MarkdownExportOptions(),+ )+ )++ assert ir.filename == "notebook.py"+ assert script.download_filename == "notebook.script.py"+ assert markdown.download_filename == "notebook.md"+++def test_from_empty_py_ir_has_exportable_default_filename() -> None:+ ir = MarimoConvert.from_py("").to_ir()++ assert ir.filename == "notebook.py"++def test_unparsable_cell_with_escaped_quotes():"""Test an unparsable cell with escaped quotes."""marimo_script = dedent(rf'''diff --git a/tests/_plugins/stateless/test_callout.py b/tests/_plugins/stateless/test_callout.pyindex 42575236bc..eaf44baf18 100644--- a/tests/_plugins/stateless/test_callout.py+++ b/tests/_plugins/stateless/test_callout.py@@ -4,6 +4,8 @@ from __future__ import annotationsimport gcimport weakref+import pytest+import marimo as mofrom marimo._output.hypertext import Htmlfrom marimo._plugins.stateless.callout import callout@@ -28,6 +30,14 @@ def test_callout_with_title() -> None:assert "data-title" not in result.text+def test_callout_rejects_unknown_kind() -> None:+ with pytest.raises(+ ValueError,+ match="Unsupported callout kind: 'warning'",+ ):+ callout("Important", kind="warning") # type: ignore[arg-type]++def test_callout_retains_strong_reference_to_child() -> None:# Regression test: callout() must keep a strong reference to its child so# that wrapped UI elements are not garbage collected (the UI registry holdsdiff --git a/tests/_sql/test_sql_quoting.py b/tests/_sql/test_sql_quoting.pyindex 7e60ac28be..beec837e29 100644--- a/tests/_sql/test_sql_quoting.py+++ b/tests/_sql/test_sql_quoting.py@@ -52,9 +52,14 @@ class TestQuoteSqlIdentifier:("nested.namespace", "starrocks", "`nested.namespace`"),("has`backtick", "starrocks", "`has``backtick`"),('has"quotes', "starrocks", '`has"quotes`'),- # Unknown dialect returns unquoted- ("table", "sqlite", "table"),- ("my table", "unknown", "my table"),+ # Unknown dialects safely default to ANSI double quotes+ ("table", "sqlite", '"table"'),+ ("my table", "unknown", '"my table"'),+ (+ 'my table; DROP TABLE "x',+ "sqlite",+ '"my table; DROP TABLE ""x"',+ ),],)def test_quote_identifier(