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: don't write snapshots on empty session views (#5684)
Myles Scolnick94fd53c8f626
diff --git a/marimo/_ast/app.py b/marimo/_ast/app.pyindex 862d2967a8..24c2e47cbb 100644--- a/marimo/_ast/app.py+++ b/marimo/_ast/app.py@@ -25,6 +25,7 @@ from uuid import uuid4from marimo._ast.app_config import _AppConfigfrom marimo._ast.variables import BUILTINS+from marimo._convert.converters import MarimoConvertfrom marimo._schemas.serialization import (AppInstantiation,CellDef,@@ -826,3 +827,6 @@ class InternalApp:options=self._app._config.asdict(),),)++ def to_py(self) -> str:+ return MarimoConvert.from_ir(self.to_ir()).to_py()diff --git a/marimo/_pyodide/pyodide_session.py b/marimo/_pyodide/pyodide_session.pyindex 58ae7f6561..0ea2b1060d 100644--- a/marimo/_pyodide/pyodide_session.py+++ b/marimo/_pyodide/pyodide_session.py@@ -330,7 +330,8 @@ class PyodideBridge:def export_html(self, request: str) -> str:parsed = parse_raw(json.loads(request), ExportAsHTMLRequest)html, _filename = Exporter().export_as_html(- file_manager=self.session.app_manager,+ app=self.session.app_manager.app,+ filename=self.session.app_manager.filename,session_view=self.session.session_view,display_config=self.session._initial_user_config["display"],request=parsed,diff --git a/marimo/_server/api/endpoints/export.py b/marimo/_server/api/endpoints/export.pyindex 340248090c..96e34ddbe0 100644--- a/marimo/_server/api/endpoints/export.py+++ b/marimo/_server/api/endpoints/export.py@@ -70,7 +70,8 @@ async def export_as_html(body.include_code = Falsehtml, filename = Exporter().export_as_html(- file_manager=session.app_file_manager,+ app=session.app_file_manager.app,+ filename=session.app_file_manager.filename,session_view=session.session_view,display_config=session.config_manager.get_config()["display"],request=body,@@ -113,6 +114,9 @@ async def auto_export_as_html(app_state = AppState(request)body = await parse_request(request, cls=ExportAsHTMLRequest)session = app_state.require_current_session()++ # Reload the file manager to get the latest state+ session.app_file_manager.reload()session_view = session.session_viewif not session.app_file_manager.is_notebook_named:@@ -126,11 +130,14 @@ async def auto_export_as_html(LOGGER.debug("Already auto-exported to HTML")return PlainTextResponse(status_code=HTTPStatus.NOT_MODIFIED)- # Reload the file manager to get the latest state- session.app_file_manager.reload()+ # If session_view is empty (no outputs), don't export+ if session_view.is_empty():+ LOGGER.info("No outputs to export")+ return PlainTextResponse(status_code=HTTPStatus.NOT_MODIFIED)html, _filename = Exporter().export_as_html(- file_manager=session.app_file_manager,+ app=session.app_file_manager.app,+ filename=session.app_file_manager.filename,session_view=session_view,display_config=session.config_manager.get_config()["display"],request=body,@@ -138,7 +145,7 @@ async def auto_export_as_html(# Save the HTML file to disk, at `.marimo/<filename>.html`await auto_exporter.save_html(- file_manager=session.app_file_manager,+ filename=session.app_file_manager.filename,html=html,)session_view.mark_auto_export_html()@@ -173,7 +180,8 @@ async def export_as_script(session = app_state.require_current_session()python, filename = Exporter().export_as_script(- file_manager=session.app_file_manager,+ app=session.app_file_manager.app,+ filename=session.app_file_manager.filename,)if body.download:@@ -286,7 +294,7 @@ async def auto_export_as_markdown(# Save the Markdown file to disk, at `.marimo/<filename>.md`await auto_exporter.save_md(- file_manager=session.app_file_manager,+ filename=session.app_file_manager.filename,markdown=markdown,)session_view.mark_auto_export_md()@@ -335,14 +343,15 @@ async def auto_export_as_ipynb(session.app_file_manager.reload()ipynb, _filename = Exporter().export_as_ipynb(- file_manager=session.app_file_manager,+ app=session.app_file_manager.app,+ filename=session.app_file_manager.filename,sort_mode="top-down",session_view=session_view,)# Save the IPYNB file to disk, at `.marimo/<filename>.ipynb`await auto_exporter.save_ipynb(- file_manager=session.app_file_manager,+ filename=session.app_file_manager.filename,ipynb=ipynb,)session_view.mark_auto_export_ipynb()diff --git a/marimo/_server/export/__init__.py b/marimo/_server/export/__init__.pyindex b7134b88f1..f18b6c00d1 100644--- a/marimo/_server/export/__init__.py+++ b/marimo/_server/export/__init__.py@@ -5,7 +5,7 @@ import asyncioimport osimport sysfrom dataclasses import dataclass-from typing import TYPE_CHECKING, Any, Callable, Literal, Optional, Union, cast+from typing import TYPE_CHECKING, Any, Callable, Literal, Optional, castfrom marimo import _loggersfrom marimo._cli.print import echo@@ -51,7 +51,10 @@ def export_as_script(assert file_key is not Nonefile_manager = file_router.get_file_manager(file_key)- result = Exporter().export_as_script(file_manager)+ result = Exporter().export_as_script(+ filename=file_manager.filename,+ app=file_manager.app,+ )return ExportResult(contents=result[0],download_filename=result[1],@@ -92,7 +95,11 @@ def export_as_ipynb(assert file_key is not Nonefile_manager = file_router.get_file_manager(file_key)- result = Exporter().export_as_ipynb(file_manager, sort_mode=sort_mode)+ result = Exporter().export_as_ipynb(+ filename=file_manager.filename,+ app=file_manager.app,+ sort_mode=sort_mode,+ )return ExportResult(contents=result[0],download_filename=result[1],@@ -115,7 +122,8 @@ def export_as_wasm(config = get_default_config_manager(current_path=file_manager.path)result = Exporter().export_as_wasm(- file_manager=file_manager,+ filename=file_manager.filename,+ app=file_manager.app,display_config=config.get_config()["display"],mode=mode,code=file_manager.to_code(),@@ -130,18 +138,15 @@ def export_as_wasm(async def run_app_then_export_as_ipynb(- path_or_file_manager: Union[MarimoPath, AppFileManager],+ filepath: MarimoPath,sort_mode: Literal["top-down", "topological"],cli_args: SerializedCLIArgs,argv: list[str] | None,) -> ExportResult:- if isinstance(path_or_file_manager, AppFileManager):- file_manager = path_or_file_manager- else:- file_router = AppFileRouter.from_filename(path_or_file_manager)- file_key = file_router.get_unique_file_key()- assert file_key is not None- file_manager = file_router.get_file_manager(file_key)+ file_router = AppFileRouter.from_filename(filepath)+ file_key = file_router.get_unique_file_key()+ assert file_key is not None+ file_manager = file_router.get_file_manager(file_key)with patch_html_for_non_interactive_output():(session_view, did_error) = await run_app_until_completion(@@ -151,7 +156,10 @@ async def run_app_then_export_as_ipynb()result = Exporter().export_as_ipynb(- file_manager, sort_mode=sort_mode, session_view=session_view+ filename=file_manager.filename,+ app=file_manager.app,+ sort_mode=sort_mode,+ session_view=session_view,)return ExportResult(contents=result[0],@@ -183,7 +191,8 @@ async def run_app_then_export_as_html()# Export the session as HTMLhtml, filename = Exporter().export_as_html(- file_manager=file_manager,+ filename=file_manager.filename,+ app=file_manager.app,session_view=session_view,display_config=config.get_config()["display"],request=ExportAsHTMLRequest(diff --git a/marimo/_server/export/exporter.py b/marimo/_server/export/exporter.pyindex da9c8a98b2..3a62f090ec 100644--- a/marimo/_server/export/exporter.py+++ b/marimo/_server/export/exporter.py@@ -16,6 +16,7 @@ from typing import ()from marimo import __version__, _loggers+from marimo._ast.app import InternalAppfrom marimo._ast.cell import Cell, CellImplfrom marimo._ast.names import DEFAULT_CELL_NAME, is_internal_cell_namefrom marimo._ast.visitor import Language@@ -39,7 +40,6 @@ from marimo._server.export.utils import (get_markdown_from_cell,get_sql_options_from_cell,)-from marimo._server.file_manager import AppFileManagerfrom marimo._server.models.export import ExportAsHTMLRequestfrom marimo._server.session.serialize import (serialize_notebook,@@ -70,34 +70,37 @@ class Exporter:def export_as_html(self,*,- file_manager: AppFileManager,+ filename: Optional[str],+ app: InternalApp,session_view: SessionView,display_config: DisplayConfig,request: ExportAsHTMLRequest,) -> tuple[str, str]:index_html = get_html_contents()- filename = get_filename(file_manager.filename)+ filename = get_filename(filename)- files: dict[str, str] = {}+ virtual_files: dict[str, str] = {}for filename_and_length in request.files:- if filename_and_length.startswith("/@file/"):- filename = filename_and_length[7:]- try:- byte_length, basename = filename.split("-", 1)- buffer_contents = read_virtual_file(basename, int(byte_length))- except Exception as e:- LOGGER.warning(- "File not found in export: %s. Error: %s",- filename_and_length,- e,+ if "@file/" in filename_and_length:+ virtual_file = filename_and_length[7:]+ try:+ byte_length, basename = virtual_file.split("-", 1)+ buffer_contents = read_virtual_file(+ basename, int(byte_length)+ )+ except Exception as e:+ LOGGER.warning(+ "File not found in export: %s. Error: %s",+ filename_and_length,+ e,+ )+ continue+ mime_type = mimetypes.guess_type(basename)[0] or "text/plain"+ virtual_files[filename_and_length] = build_data_url(+ cast(KnownMimeType, mime_type),+ base64.b64encode(buffer_contents),)- continue- mime_type = mimetypes.guess_type(basename)[0] or "text/plain"- files[filename_and_length] = build_data_url(- cast(KnownMimeType, mime_type),- base64.b64encode(buffer_contents),- )# We only want pass the display config in the static notebook,# since we use:@@ -107,11 +110,9 @@ class Exporter:config["display"] = display_configsession_snapshot = serialize_session_view(- session_view, cell_ids=file_manager.app.cell_manager.cell_ids()- )- notebook_snapshot = serialize_notebook(- session_view, file_manager.app.cell_manager+ session_view, cell_ids=app.cell_manager.cell_ids())+ notebook_snapshot = serialize_notebook(session_view, app.cell_manager)if not request.include_code:code = ""# Clear code and console outputs@@ -121,37 +122,36 @@ class Exporter:for output in session_snapshot["cells"]:output["console"] = []else:- code = file_manager.to_code()+ code = app.to_py()# We include the code hash regardless of whether we include the code- code_hash = hash_code(file_manager.to_code())+ code_hash = hash_code(app.to_py())html = static_notebook_template(html=index_html,user_config=config,config_overrides={},server_token=SkewProtectionToken("static"),- app_config=file_manager.app.config,- filepath=file_manager.filename,+ app_config=app.config,+ filepath=filename,code=code,code_hash=code_hash,session_snapshot=session_snapshot,notebook_snapshot=notebook_snapshot,- files=files,+ files=virtual_files,asset_url=request.asset_url,)- download_filename = get_download_filename(- file_manager.filename, "html"- )+ download_filename = get_download_filename(filename, "html")return html, download_filenamedef export_as_script(self,- file_manager: AppFileManager,+ filename: Optional[str],+ app: InternalApp,) -> tuple[str, str]:# Check if any code is async, if so, raise an error- for cell in file_manager.app.cell_manager.cells():+ for cell in app.cell_manager.cells():if not cell:continueif cell._is_coroutine:@@ -161,21 +161,20 @@ class Exporter:"Cannot export a notebook with async code to a flat script")- graph = file_manager.app.graph+ graph = app.graphcodes: list[str] = ["# %%\n" + graph.cells[cid].codefor cid in dataflow.topological_sort(graph, graph.cells.keys())]code = f'\n__generated_with = "{__version__}"\n\n' + "\n\n".join(codes)- download_filename = get_download_filename(- file_manager.filename, "script.py"- )+ download_filename = get_download_filename(filename, "script.py")return code, download_filenamedef export_as_ipynb(self,- file_manager: AppFileManager,+ app: InternalApp,+ filename: Optional[str],sort_mode: Literal["top-down", "topological"],session_view: Optional[SessionView] = None,) -> tuple[str, str]:@@ -186,11 +185,11 @@ class Exporter:import nbformat # type: ignore[import-not-found]notebook = nbformat.v4.new_notebook() # type: ignore[no-untyped-call]- graph = file_manager.app.graph+ graph = app.graph# Sort cells based on sort_modeif sort_mode == "top-down":- cell_ids = list(file_manager.app.cell_manager.cell_ids())+ cell_ids = list(app.cell_manager.cell_ids())else:cell_ids = dataflow.topological_sort(graph, graph.cells.keys())@@ -221,7 +220,7 @@ class Exporter:marimo_metadata["config"] = (cell.config.asdict_without_defaults())- name = file_manager.app.cell_manager.cell_name(cid)+ name = app.cell_manager.cell_name(cid)if not is_internal_cell_name(name):marimo_metadata["name"] = nameif marimo_metadata:@@ -233,9 +232,7 @@ class Exporter:stream = io.StringIO()nbformat.write(notebook, stream) # type: ignore[no-untyped-call]stream.seek(0)- download_filename = get_download_filename(- file_manager.filename, "ipynb"- )+ download_filename = get_download_filename(filename, "ipynb")return stream.read(), download_filenamedef export_as_md(@@ -390,7 +387,8 @@ class Exporter:def export_as_wasm(self,*,- file_manager: AppFileManager,+ app: InternalApp,+ filename: Optional[str],display_config: DisplayConfig,code: str,mode: Literal["edit", "run"],@@ -399,7 +397,7 @@ class Exporter:) -> tuple[str, str]:"""Export notebook as a WASM-powered standalone HTML file."""index_html = get_html_contents()- filename = get_filename(file_manager.filename)+ filename = get_filename(filename)# We only want to pass the display config in the static notebookconfig: MarimoConfig = deep_copy(DEFAULT_CONFIG)@@ -414,15 +412,13 @@ class Exporter:mode=mode,user_config=config,config_overrides={},- app_config=file_manager.app.config,+ app_config=app.config,code=code,asset_url=asset_url,show_code=show_code,)- download_filename = get_download_filename(- file_manager.filename, "wasm.html"- )+ download_filename = get_download_filename(filename, "wasm.html")return html, download_filename@@ -490,10 +486,10 @@ class AutoExporter:)async def _save_file(- self, file_manager: AppFileManager, content: str, extension: str+ self, filename: Optional[str], content: str, extension: str) -> None:- directory = Path(get_filename(file_manager.filename)).parent- filename = get_download_filename(file_manager.filename, extension)+ directory = Path(get_filename(filename)).parent+ filename = get_download_filename(filename, extension)await self._ensure_export_dir_async(directory)filepath = directory / self.EXPORT_DIR / filename@@ -504,18 +500,14 @@ class AutoExporter:self._executor, self._write_file_sync, filepath, content)- async def save_html(self, file_manager: AppFileManager, html: str) -> None:- await self._save_file(file_manager, html, "html")+ async def save_html(self, filename: Optional[str], html: str) -> None:+ await self._save_file(filename, html, "html")- async def save_md(- self, file_manager: AppFileManager, markdown: str- ) -> None:- await self._save_file(file_manager, markdown, "md")+ async def save_md(self, filename: Optional[str], markdown: str) -> None:+ await self._save_file(filename, markdown, "md")- async def save_ipynb(- self, file_manager: AppFileManager, ipynb: str- ) -> None:- await self._save_file(file_manager, ipynb, "ipynb")+ async def save_ipynb(self, filename: Optional[str], ipynb: str) -> None:+ await self._save_file(filename, ipynb, "ipynb")def _write_file_sync(self, filepath: Path, content: str) -> None:"""Synchronous file write (runs in thread pool)"""diff --git a/marimo/_server/session/serialize.py b/marimo/_server/session/serialize.pyindex ca7254bbd7..1488436b3d 100644--- a/marimo/_server/session/serialize.py+++ b/marimo/_server/session/serialize.py@@ -440,10 +440,8 @@ class SessionCacheManager:return self.session_viewif not self.is_cache_hit(notebook_session, key):- LOGGER.debug("Session view cache miss")+ LOGGER.info("Session view cache miss")return self.session_view- self.session_view = deserialize_session(- json.loads(cache_file.read_text())- )+ self.session_view = deserialize_session(notebook_session)return self.session_viewdiff --git a/marimo/_server/session/session_view.py b/marimo/_server/session/session_view.pyindex ee77c2c44e..1bd21a783d 100644--- a/marimo/_server/session/session_view.py+++ b/marimo/_server/session/session_view.py@@ -323,6 +323,12 @@ class SessionView:all_ops.extend(messages)return all_ops+ def is_empty(self) -> bool:+ return all(+ op.output is None and op.console is None+ for op in self.cell_operations.values()+ )+def mark_auto_export_html(self) -> None:self.auto_export_state.mark_exported("html")diff --git a/tests/_ast/test_app.py b/tests/_ast/test_app.pyindex 226b94b42b..53f3968458 100644--- a/tests/_ast/test_app.py+++ b/tests/_ast/test_app.py@@ -742,6 +742,32 @@ class TestApp:InternalApp(app).cell_manager.cell_ids())+ def test_to_py(self) -> None:+ """Test that InternalApp.to_py() returns the Python code representation."""+ app = App()++ @app.cell+ def cell_one():+ x = 1+ return (x,)++ @app.cell+ def cell_two(x):+ y = x + 1+ return (y,)++ internal_app = InternalApp(app)+ python_code = internal_app.to_py()++ # Verify it returns a string containing Python code+ assert isinstance(python_code, str)+ assert "import marimo" in python_code+ assert "app = marimo.App(" in python_code+ assert "x = 1" in python_code+ assert "y = x + 1" in python_code+ assert "cell_one" in python_code+ assert "cell_two" in python_code+class TestInvalidSetup:@staticmethoddiff --git a/tests/_server/api/endpoints/test_export.py b/tests/_server/api/endpoints/test_export.pyindex 95affbe334..394d2b463c 100644--- a/tests/_server/api/endpoints/test_export.py+++ b/tests/_server/api/endpoints/test_export.py@@ -11,8 +11,10 @@ import pytestfrom marimo import __version__from marimo._dependencies.dependencies import DependencyManager+from marimo._messaging.cell_output import CellChannel, CellOutput+from marimo._messaging.ops import CellOpfrom marimo._output.utils import uri_encode_component-from marimo._types.ids import SessionId+from marimo._types.ids import CellId_t, SessionIdfrom marimo._utils.platform import is_windowsfrom tests._server.conftest import get_session_managerfrom tests._server.mocks import (@@ -203,6 +205,16 @@ def test_auto_export_html(client: TestClient, temp_marimo_file: str) -> None:assert sessionassert temp_marimo_file is not Nonesession.app_file_manager.filename = temp_marimo_file+ session.session_view.add_operation(+ CellOp(+ cell_id=CellId_t("new_cell"),+ output=CellOutput(+ data="hello",+ mimetype="text/plain",+ channel=CellChannel.OUTPUT,+ ),+ )+ )response = client.post("/api/export/auto_export/html",@@ -241,6 +253,13 @@ def test_auto_export_html_no_code(session = get_session_manager(client).get_session(SESSION_ID)assert sessionsession.app_file_manager.filename = temp_marimo_file+ session.session_view.add_operation(+ CellOp(+ cell_id=CellId_t("new_cell"),+ output=None,+ console=[CellOutput.stdout("hello")],+ )+ )response = client.post("/api/export/auto_export/html",@@ -272,6 +291,28 @@ def test_auto_export_html_no_code()+@with_session(SESSION_ID)+def test_auto_export_html_no_operations(+ client: TestClient, temp_marimo_file: str+) -> None:+ session = get_session_manager(client).get_session(SESSION_ID)+ assert session+ session.app_file_manager.filename = temp_marimo_file+ assert session.session_view.is_empty()++ response = client.post(+ "/api/export/auto_export/html",+ headers=HEADERS,+ json={+ "download": False,+ "files": [],+ "include_code": True,+ },+ )+ # Not modified response+ assert response.status_code == 304++@with_session(SESSION_ID)def test_auto_export_markdown(client: TestClient, *, temp_marimo_file: strdiff --git a/tests/_server/export/test_exporter.py b/tests/_server/export/test_exporter.pyindex a44fe97b7a..82cca57219 100644--- a/tests/_server/export/test_exporter.py+++ b/tests/_server/export/test_exporter.py@@ -37,11 +37,11 @@ HAS_NBFORMAT = DependencyManager.nbformat.has()@pytest.mark.skipif(not HAS_NBFORMAT, reason="nbformat is not installed")def test_export_ipynb_empty():app = App()- file_manager = AppFileManager.from_app(InternalApp(app))+ internal_app = InternalApp(app)exporter = Exporter()content, filename = exporter.export_as_ipynb(- file_manager, sort_mode="top-down"+ internal_app, None, sort_mode="top-down")assert filename == "notebook.ipynb"snapshot("empty_notebook.ipynb.txt", content)@@ -55,11 +55,11 @@ def test_export_ipynb_with_cells():def cell_1():print("hello")- file_manager = AppFileManager.from_app(InternalApp(app))+ internal_app = InternalApp(app)exporter = Exporter()content, filename = exporter.export_as_ipynb(- file_manager, sort_mode="top-down"+ internal_app, None, sort_mode="top-down")assert filename == "notebook.ipynb"snapshot("notebook_with_cells.ipynb.txt", content)@@ -84,16 +84,18 @@ def test_export_ipynb_sort_modes():y = 1return (y,)- file_manager = AppFileManager.from_app(InternalApp(app))+ internal_app = InternalApp(app)exporter = Exporter()# Test top-down mode preserves document order- content, _ = exporter.export_as_ipynb(file_manager, sort_mode="top-down")+ content, _ = exporter.export_as_ipynb(+ internal_app, None, sort_mode="top-down"+ )snapshot("notebook_top_down.ipynb.txt", content)# Test topological mode respects dependenciescontent, _ = exporter.export_as_ipynb(- file_manager, sort_mode="topological"+ internal_app, None, sort_mode="topological")snapshot("notebook_topological.ipynb.txt", content)@@ -108,7 +110,7 @@ HAS_DEPS = (# ruff: noqa: B018@pytest.mark.skipif(not HAS_DEPS, reason="optional dependencies not installed")-async def test_export_ipynb_with_outputs():+async def test_export_ipynb_with_outputs(tmp_path: Path):app = App()# stdout@@ -220,17 +222,20 @@ async def test_export_ipynb_with_outputs():# plt.plot([1, 2])# return (plt,)- file_manager = AppFileManager.from_app(InternalApp(app))+ internal_app = InternalApp(app)exporter = Exporter()content, filename = exporter.export_as_ipynb(- file_manager, sort_mode="top-down", session_view=None+ internal_app, None, sort_mode="top-down", session_view=None)assert filename == "notebook.ipynb"assert content is not None+ test_file = tmp_path / "notebook.py"+ test_file.write_text(InternalApp(app).to_py())+result = await run_app_then_export_as_ipynb(- file_manager,+ MarimoPath(test_file),sort_mode="top-down",cli_args={},argv=None,@@ -329,10 +334,11 @@ async def test_export_wasm_edit():exporter = Exporter()content, filename = exporter.export_as_wasm(- file_manager=file_manager,+ filename=file_manager.filename,+ app=file_manager.app,display_config=DEFAULT_CONFIG["display"],mode="edit",- code=file_manager.to_code(),+ code=file_manager.app.to_py(),show_code=True,)@@ -353,10 +359,11 @@ async def test_export_wasm_run():exporter = Exporter()content, filename = exporter.export_as_wasm(- file_manager=file_manager,+ filename=file_manager.filename,+ app=file_manager.app,display_config=DEFAULT_CONFIG["display"],mode="run",- code=file_manager.to_code(),+ code=file_manager.app.to_py(),show_code=True,)@@ -552,7 +559,8 @@ def test_export_as_html_with_serialization():)html, filename = exporter.export_as_html(- file_manager=file_manager,+ filename=file_manager.filename,+ app=file_manager.app,session_view=session_view,display_config=DEFAULT_CONFIG["display"],request=request,@@ -608,7 +616,8 @@ def test_export_as_html_without_code():)html, filename = exporter.export_as_html(- file_manager=file_manager,+ filename=file_manager.filename,+ app=file_manager.app,session_view=session_view,display_config=DEFAULT_CONFIG["display"],request=request,@@ -661,7 +670,8 @@ def test_export_as_html_with_files():mock_read.return_value = b"test file content"html, filename = exporter.export_as_html(- file_manager=file_manager,+ filename=file_manager.filename,+ app=file_manager.app,session_view=session_view,display_config=DEFAULT_CONFIG["display"],request=request,@@ -706,7 +716,8 @@ def test_export_as_html_with_cell_configs():)html, filename = exporter.export_as_html(- file_manager=file_manager,+ filename=file_manager.filename,+ app=file_manager.app,session_view=session_view,display_config=DEFAULT_CONFIG["display"],request=request,@@ -765,7 +776,8 @@ def test_export_as_html_preserves_output_order():)html, filename = exporter.export_as_html(- file_manager=file_manager,+ filename=file_manager.filename,+ app=file_manager.app,session_view=session_view,display_config=DEFAULT_CONFIG["display"],request=request,@@ -821,7 +833,8 @@ def test_export_as_html_with_error_outputs():)html, filename = exporter.export_as_html(- file_manager=file_manager,+ filename=file_manager.filename,+ app=file_manager.app,session_view=session_view,display_config=DEFAULT_CONFIG["display"],request=request,@@ -863,7 +876,8 @@ def test_export_as_html_code_hash_consistency():)html_with_code, _ = exporter.export_as_html(- file_manager=file_manager,+ filename=file_manager.filename,+ app=file_manager.app,session_view=session_view,display_config=DEFAULT_CONFIG["display"],request=request_with_code,@@ -877,7 +891,8 @@ def test_export_as_html_code_hash_consistency():)html_without_code, _ = exporter.export_as_html(- file_manager=file_manager,+ filename=file_manager.filename,+ app=file_manager.app,session_view=session_view,display_config=DEFAULT_CONFIG["display"],request=request_without_code,diff --git a/tests/_server/session/test_session_view.py b/tests/_server/session/test_session_view.pyindex b26d1ba6f8..7d301736ad 100644--- a/tests/_server/session/test_session_view.py+++ b/tests/_server/session/test_session_view.py@@ -926,3 +926,52 @@ def test_dataset_filter_by_engine_and_variable() -> None:session_view.add_operation(Variables(variables=[]))table_names = [t.name for t in session_view.datasets.tables]assert table_names == ["table_none"]+++def test_is_empty() -> None:+ """Test that SessionView.is_empty() correctly detects empty session views."""+ session_view = SessionView()++ # Initially empty+ assert session_view.is_empty()++ # Add a cell operation without output or console+ session_view.add_operation(+ CellOp(+ cell_id=cell_id,+ status=initial_status,+ )+ )++ # Add a cell operation+ session_view.add_operation(+ CellOp(+ cell_id=cell_id,+ output=initial_output,+ status=initial_status,+ )+ )++ # No longer empty+ assert not session_view.is_empty()++ # Clear operations by creating a new session view+ session_view = SessionView()+ assert session_view.is_empty()++ # Add multiple operations - should still not be empty+ session_view.add_operation(+ CellOp(+ cell_id="cell1",+ output=initial_output,+ status="idle",+ )+ )+ session_view.add_operation(+ CellOp(+ cell_id="cell2",+ output=updated_output,+ status="idle",+ )+ )+ assert not session_view.is_empty()