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
Ensure partial cell config update preserves existing values (#10971)
Martha Cryan53cb2bdf8d74
diff --git a/marimo/_runtime/runtime.py b/marimo/_runtime/runtime.pyindex 0d49f08ff2..03cfa9d0a6 100644--- a/marimo/_runtime/runtime.py+++ b/marimo/_runtime/runtime.py@@ -1908,16 +1908,16 @@ class Kernel:# Stale cells that are enabled will need to be run.stale_cells: set[CellId_t] = set()for cell_id, config in request.configs.items():- # store the config, regardless of whether we've seen the cell yet- self.cell_metadata[cell_id] = CellMetadata(- config=CellConfig.from_dict(config)- )+ previous = self.cell_metadata.get(cell_id, CellMetadata()).config+ merged = CellConfig.from_dict(previous.asdict())+ merged.configure(config)+ self.cell_metadata[cell_id] = CellMetadata(config=merged)cell = self.graph.cells.get(cell_id)if cell is None:continuecell.configure(config)if not cell.config.disabled:- stale_cells = self.graph.enable_cell(cell_id)+ stale_cells |= self.graph.enable_cell(cell_id)elif cell.config.disabled:self.graph.disable_cell(cell_id)diff --git a/tests/_runtime/test_runtime.py b/tests/_runtime/test_runtime.pyindex c564e795aa..dc208d32a7 100644--- a/tests/_runtime/test_runtime.py+++ b/tests/_runtime/test_runtime.py@@ -3229,6 +3229,77 @@ class TestDisable:assert not k.graph.cells[er_2.cell_id].disabled_transitivelyassert k.graph.cells[er_2.cell_id].runtime_state == "idle"+ async def test_partial_config_update_preserves_disabled(+ self, any_kernel: Kernel, exec_req: ExecReqProvider+ ) -> None:+ """Config updates are partial: omitted keys keep their value.++ Regression test: toggling `expand_output` on a disabled cell used to+ drop `disabled` from the cell's stored metadata, so the cell ran the+ next time it was registered.+ """+ k = any_kernel+ er_1 = exec_req.get("x = 0")+ await k.run([er_1])++ await k.set_cell_config(+ UpdateCellConfigCommand(configs={er_1.cell_id: {"disabled": True}})+ )+ await k.set_cell_config(+ UpdateCellConfigCommand(+ configs={er_1.cell_id: {"expand_output": True}}+ )+ )+ assert k.cell_metadata[er_1.cell_id].config.disabled+ assert k.cell_metadata[er_1.cell_id].config.expand_output++ # editing the cell's code re-registers it, restoring the stored config+ await k.run([exec_req.get_with_id(er_1.cell_id, "x = 1")])+ assert k.graph.cells[er_1.cell_id].config.disabled+ assert k.graph.cells[er_1.cell_id].config.expand_output+ assert "x" not in k.globals++ async def test_enable_many_cells_runs_all_stale_cells(+ self, any_kernel: Kernel, exec_req: ExecReqProvider+ ) -> None:+ """Enabling several cells at once re-runs every stale one."""+ k = any_kernel+ await k.run(+ [+ er_1 := exec_req.get("x = 0"),+ er_2 := exec_req.get("y = 0"),+ ]+ )+ configs = {+ er_1.cell_id: {"disabled": True},+ er_2.cell_id: {"disabled": True},+ }+ await k.set_cell_config(UpdateCellConfigCommand(configs=configs))++ # make both cells stale while disabled+ await k.run(+ [+ er_1 := exec_req.get_with_id(er_1.cell_id, "x = 1"),+ er_2 := exec_req.get_with_id(er_2.cell_id, "y = 1"),+ ]+ )+ assert k.graph.get_stale() == {er_1.cell_id, er_2.cell_id}++ # re-enable both in a single request+ await k.set_cell_config(+ UpdateCellConfigCommand(+ configs={+ er_1.cell_id: {"disabled": False},+ er_2.cell_id: {"disabled": False},+ }+ )+ )+ if k.lazy():+ await k.run([er_1, er_2])+ assert k.globals["x"] == 1+ assert k.globals["y"] == 1+ assert not k.graph.get_stale()+class TestAsyncIO:@staticmethod