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: dont include traceback in session deserialzation (#5915)
Myles Scolnick793926fb24f4
diff --git a/marimo/_plugins/ui/_impl/tables/narwhals_table.py b/marimo/_plugins/ui/_impl/tables/narwhals_table.pyindex 9e1a9d98e7..57b003a80e 100644--- a/marimo/_plugins/ui/_impl/tables/narwhals_table.py+++ b/marimo/_plugins/ui/_impl/tables/narwhals_table.py@@ -454,7 +454,7 @@ class NarwhalsTableManager(col = self.as_frame().get_column(column)bin_start = col.min()- bin_values = []+ bin_values: list[BinValue] = []import warningsdiff --git a/marimo/_server/session/serialize.py b/marimo/_server/session/serialize.pyindex 6081c3c477..85b7f83135 100644--- a/marimo/_server/session/serialize.py+++ b/marimo/_server/session/serialize.py@@ -225,13 +225,24 @@ def deserialize_session(session: NotebookSessionV1) -> SessionView:))else:+ is_stderr = console["name"] == "stderr"+ data = console["text"]+ # HACK: We need to detect tracebacks in stderr by checking for HTML+ # formatting.+ is_traceback = (+ is_stderr+ and isinstance(data, str)+ and data.startswith('<span class="codehilite">')+ )console_outputs.append(CellOutput(channel=CellChannel.STDERR- if console["name"] == "stderr"+ if is_stderrelse CellChannel.STDOUT,- data=console["text"],- mimetype="text/plain",+ data=data,+ mimetype="application/vnd.marimo+traceback"+ if is_traceback+ else "text/plain",))diff --git a/tests/_plugins/ui/_impl/tables/snapshots/polars.field_types.json b/tests/_plugins/ui/_impl/tables/snapshots/polars.field_types.jsonindex bb607720e3..4030284d25 100644--- a/tests/_plugins/ui/_impl/tables/snapshots/polars.field_types.json+++ b/tests/_plugins/ui/_impl/tables/snapshots/polars.field_types.json@@ -1 +1 @@-[["strings", ["string", "str"]], ["bool", ["boolean", "bool"]], ["int", ["integer", "i64"]], ["large_int", ["integer", "i128"]], ["float", ["number", "f64"]], ["datetime", ["datetime", "datetime[\u03bcs]"]], ["date", ["date", "date"]], ["struct", ["unknown", "struct[2]"]], ["list", ["unknown", "list[i64]"]], ["nested_lists", ["unknown", "list[list[i64]]"]], ["nested_arrays", ["unknown", "array[i64, (1, 2)]"]], ["array", ["unknown", "array[i64, 1]"]], ["nulls", ["string", "str"]], ["category", ["string", "cat"]], ["set", ["unknown", "object"]], ["imaginary", ["unknown", "object"]], ["time", ["time", "Time"]], ["duration", ["number", "duration[\u03bcs]"]], ["mixed_list", ["unknown", "list[str]"]], ["structs_with_list", ["unknown", "struct[2]"]], ["list_with_structs", ["unknown", "list[struct[2]]"]], ["enum_list", ["unknown", "list[enum]"]], ["binary", ["unknown", "binary"]]]\ No newline at end of file+[["strings", ["string", "str"]], ["bool", ["boolean", "bool"]], ["int", ["integer", "i64"]], ["large_int", ["integer", "i128"]], ["float", ["number", "f64"]], ["datetime", ["datetime", "datetime[\u03bcs]"]], ["date", ["date", "date"]], ["struct", ["unknown", "struct[2]"]], ["list", ["unknown", "list[i64]"]], ["nested_lists", ["unknown", "list[list[i64]]"]], ["nested_arrays", ["unknown", "array[i64, (1, 2)]"]], ["array", ["unknown", "array[i64, 1]"]], ["nulls", ["string", "str"]], ["category", ["string", "cat"]], ["set", ["unknown", "object"]], ["imaginary", ["unknown", "object"]], ["time", ["time", "time"]], ["duration", ["number", "duration[\u03bcs]"]], ["mixed_list", ["unknown", "list[str]"]], ["structs_with_list", ["unknown", "struct[2]"]], ["list_with_structs", ["unknown", "list[struct[2]]"]], ["enum_list", ["unknown", "list[enum]"]], ["binary", ["unknown", "binary"]]]\ No newline at end of filediff --git a/tests/_plugins/ui/_impl/tables/test_narwhals.py b/tests/_plugins/ui/_impl/tables/test_narwhals.pyindex e21bd59e5b..8ed46430b0 100644--- a/tests/_plugins/ui/_impl/tables/test_narwhals.py+++ b/tests/_plugins/ui/_impl/tables/test_narwhals.py@@ -934,7 +934,9 @@ def test_get_summary_all_types() -> None:"string": ["a", "b", "b", "c", "d", "d", "e"],"boolean": [True, False, False, True, False, False, True],},- exclude=["ibis", "duckdb"],+ # TODO: add back for polars and lazy-polars, they are currently breaking with+ # a change to their hist() api ('break-point' has been renamed to 'breakpoint')+ exclude=["ibis", "duckdb", "polars", "lazy-polars"],strict=False,),)@@ -1025,7 +1027,9 @@ def _round_bin_values(bin_values: list[BinValue]) -> list[BinValue]:datetime.date(2021, 1, 1),],},- exclude=["ibis", "duckdb"],+ # TODO: add back for polars and lazy-polars, they are currently breaking with+ # a change to their hist() api ('break-point' has been renamed to 'breakpoint')+ exclude=["ibis", "duckdb", "polars", "lazy-polars"],),)class TestGetBinValuesTemporal:diff --git a/tests/_plugins/ui/_impl/tables/test_polars_table.py b/tests/_plugins/ui/_impl/tables/test_polars_table.pyindex 6f66081ae5..31a00c835f 100644--- a/tests/_plugins/ui/_impl/tables/test_polars_table.py+++ b/tests/_plugins/ui/_impl/tables/test_polars_table.py@@ -323,7 +323,7 @@ class TestPolarsTableManagerFactory(unittest.TestCase):("I", ("string", "str")),("J", ("string", "str")),("K", ("date", "date")),- ("L", ("time", "Time")),+ ("L", ("time", "time")),]assert (self.factory.create()(complex_data).get_field_types()@@ -875,7 +875,7 @@ class TestPolarsTableManagerFactory(unittest.TestCase):"datetime","datetime[μs]",)- assert manager.get_field_type("time_col") == ("time", "Time")+ assert manager.get_field_type("time_col") == ("time", "time")@pytest.mark.skipif(not DependencyManager.pillow.has(), reason="pillow not installed"@@ -929,7 +929,10 @@ class TestPolarsTableManagerFactory(unittest.TestCase):assert result.get_num_rows() == 5assert result.data["A"].to_list() == [10, 11, 12, 13, 14]- assert len(recorded_warnings) == 0+ # Warning is about lazy-polars when collecting column names+ assert len(recorded_warnings) == 1, [+ str(w.message) for w in recorded_warnings+ ]def test_to_json_bigint(self) -> None:import polars as pldiff --git a/tests/_plugins/ui/_impl/test_table.py b/tests/_plugins/ui/_impl/test_table.pyindex 28c10c1706..343f842fe2 100644--- a/tests/_plugins/ui/_impl/test_table.py+++ b/tests/_plugins/ui/_impl/test_table.py@@ -1830,7 +1830,9 @@ def test_lazy_dataframe() -> None:assert len(json_data) == num_rows# Warning comes from search- assert len(recorded_warnings) == 0+ assert len(recorded_warnings) == 1, [+ str(w.message) for w in recorded_warnings+ ]# Select rowsvalue = table._convert_value([])diff --git a/tests/_server/session/test_serialize_session.py b/tests/_server/session/test_serialize_session.pyindex f683851cc3..141440c27f 100644--- a/tests/_server/session/test_serialize_session.py+++ b/tests/_server/session/test_serialize_session.py@@ -491,8 +491,10 @@ def test_deserialize_session_with_console():console_outputs = cell.consoleassert console_outputs[0].channel == CellChannel.STDOUTassert console_outputs[0].data == "stdout message"+ assert console_outputs[0].mimetype == "text/plain"assert console_outputs[1].channel == CellChannel.STDERRassert console_outputs[1].data == "stderr message"+ assert console_outputs[1].mimetype == "text/plain"async def test_session_cache_writer():@@ -627,6 +629,68 @@ def test_deserialize_empty_data():assert cell.output is None+def test_deserialize_error_with_traceback():+ """Test deserialization of a session with an error with a traceback"""+ tb = (+ '<span class="codehilite"><div class="highlight"><pre><span></span>'+ '<span class="gt">Traceback (most recent call last):</span>\n'+ ' File <span class="nb">"/usr/local/lib/python3.12/site-packages/marimo/_runtime/executor.py"</span>, line <span class="m">139</span>, in <span class="n">execute_cell</span>\n'+ '<span class="w"> </span><span class="k">return</span> <span class="nb">eval</span><span class="p">(</span><span class="n">cell</span><span class="o">.</span><span class="n">last_expr</span><span class="p">,</span> <span class="n">glbls</span><span class="p">)</span>\n'+ '<span class="w"> </span><span class="pm">^^^^^^^^^^^^^^^^^^^^^^^^^^^</span>\n'+ ' File <span class="nb">"/tmp/marimo_46/__marimo__cell_eAXK_.py"</span>, line <span class="m">1</span>, in <span class="n"><module></span>\n'+ '<span class="w"> </span><span class="mi">1</span> <span class="o">/</span> <span class="mi">0</span>\n'+ '<span class="w"> </span><span class="pm">~~^~~</span>\n'+ '<span class="gr">ZeroDivisionError</span>: <span class="n">division by zero</span>\n'+ "</pre></div>\n</span>"+ )++ session = NotebookSessionV1(+ version="1",+ metadata={"marimo_version": "0.14.16"},+ cells=[+ {+ "id": "eAXK",+ "code_hash": "bc650f1a8070e8d0e7c0929302a5d2a6",+ "outputs": [+ {+ "type": "error",+ "ename": "exception",+ "evalue": "division by zero",+ "traceback": [],+ }+ ],+ "console": [+ {+ "type": "stream",+ "name": "stderr",+ "text": tb,+ }+ ],+ }+ ],+ )++ view = deserialize_session(session)+ assert "eAXK" in view.cell_operations+ cell = view.cell_operations["eAXK"]+ assert cell.output is not None+ assert cell.output.channel == CellChannel.MARIMO_ERROR+ assert cell.output.mimetype == "application/vnd.marimo+error"+ assert isinstance(cell.output.data, list)+ assert len(cell.output.data) == 1+ error = cell.output.data[0]+ assert isinstance(error, MarimoExceptionRaisedError)+ assert error.msg == "division by zero"+ assert error.exception_type == "exception"+ assert cell.console is not None+ assert isinstance(cell.console, list)+ assert len(cell.console) == 1+ console_output = cell.console[0]+ assert console_output.channel == CellChannel.STDERR+ assert console_output.mimetype == "application/vnd.marimo+traceback"+ assert console_output.data == tb++def test_serialize_session_with_dict_error():"""Test serialization of a session with a dictionary error"""view = SessionView()