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: renaming a file extension should save in file format (#1423)
Dylan Madisetti88d797548f0b
diff --git a/marimo/_server/file_manager.py b/marimo/_server/file_manager.pyindex dfcd98e699..d27e2ac9c7 100644--- a/marimo/_server/file_manager.py+++ b/marimo/_server/file_manager.py@@ -138,12 +138,26 @@ class AppFileManager:self._assert_path_does_not_exist(new_filename)- if self._is_named():+ need_save = False+ # Check if filename is not None to satisfy mypy's type checking.+ # This ensures that filename is treated as a non-optional str,+ # preventing potential type errors in subsequent code.+ if self._is_named() and self.filename is not None:+ # Force a save after rename in case filetype changed.+ need_save = self.filename[-3:] != new_filename[-3:]self._rename_file(new_filename)else:self._create_file(new_filename)self.filename = new_filename+ if need_save:+ self._save_file(+ self.filename,+ list(self.app.cell_manager.codes()),+ list(self.app.cell_manager.names()),+ list(self.app.cell_manager.configs()),+ self.app.config,+ )def read_layout_config(self) -> Optional[LayoutConfig]:if self.app.config.layout_file is not None and isinstance(diff --git a/tests/_server/test_file_manager.py b/tests/_server/test_file_manager.pyindex d77c0d962a..2e1a14a7ee 100644--- a/tests/_server/test_file_manager.py+++ b/tests/_server/test_file_manager.py@@ -106,6 +106,21 @@ def test_rename_create_new_file(app_file_manager: AppFileManager) -> None:os.remove(new_filename)+def test_rename_different_filetype(app_file_manager: AppFileManager) -> None:+ initial_filename = app_file_manager.filename+ assert initial_filename.endswith(".py")+ with open(app_file_manager.filename, "r") as f:+ contents = f.read()+ assert "app = marimo.App()" in contents+ assert "marimo-version" not in contents+ app_file_manager.rename(initial_filename[:-3] + ".md")+ assert app_file_manager.filename.endswith(".md")+ with open(app_file_manager.filename, "r") as f:+ contents = f.read()+ assert "marimo-version" in contents+ assert "app = marimo.App()" not in contents++def test_save_app_config_valid(app_file_manager: AppFileManager) -> None:app_file_manager.filename = "app_config.py"try: