Skip to content

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.

fix: don't autorun on rename when runtime is lazy (#1999)

Akshay Agrawalb56ef1280db6
diff --git a/marimo/_runtime/runtime.py b/marimo/_runtime/runtime.py
index 5c99bdfe2b..da6bf17cc5 100644
--- a/marimo/_runtime/runtime.py
+++ b/marimo/_runtime/runtime.py
@@ -956,6 +956,14 @@ class Kernel:
break
LOGGER.debug("Finished run.")
+ async def _if_autorun_then_run_cells(
+ self, cell_ids: set[CellId_t]
+ ) -> None:
+ if self.reactive_execution_mode == "autorun":
+ await self._run_cells(cell_ids)
+ else:
+ self.graph.set_stale(cell_ids)
+
def _broadcast_missing_packages(self, runner: cell_runner.Runner) -> None:
if (
any(
@@ -1123,7 +1131,7 @@ class Kernel:
for cell in self.graph.cells.values():
if "__file__" in cell.refs:
roots.add(cell.cell_id)
- await self._run_cells(roots)
+ await self._if_autorun_then_run_cells(roots)
async def run_scratchpad(self, code: str) -> None:
roots = {SCRATCH_CELL_ID}
@@ -1564,12 +1572,7 @@ class Kernel:
if (cid := self.module_registry.defining_cell(module)) is not None
)
if cells_to_run:
- if self.reactive_execution_mode == "autorun":
- await self._run_cells(
- dataflow.transitive_closure(self.graph, cells_to_run)
- )
- else:
- self.graph.set_stale(cells_to_run)
+ await self._if_autorun_then_run_cells(cells_to_run)
async def preview_dataset_column(
self, request: PreviewDatasetColumnRequest
diff --git a/tests/_data/snapshots/charts_json.txt b/tests/_data/snapshots/charts_json.txt
index b4eac8a7c0..09055d6335 100644
--- a/tests/_data/snapshots/charts_json.txt
+++ b/tests/_data/snapshots/charts_json.txt
@@ -1,6 +1,6 @@
# boolean
{
- "$schema": "https://vega.github.io/schema/vega-lite/v5.17.0.json",
+ "$schema": "https://vega.github.io/schema/vega-lite/v5.20.1.json",
"config": {
"view": {
"continuousHeight": 300,
@@ -41,7 +41,7 @@
# date
{
- "$schema": "https://vega.github.io/schema/vega-lite/v5.17.0.json",
+ "$schema": "https://vega.github.io/schema/vega-lite/v5.20.1.json",
"config": {
"view": {
"continuousHeight": 300,
@@ -86,7 +86,7 @@
# integer
{
- "$schema": "https://vega.github.io/schema/vega-lite/v5.17.0.json",
+ "$schema": "https://vega.github.io/schema/vega-lite/v5.20.1.json",
"config": {
"view": {
"continuousHeight": 300,
@@ -128,7 +128,7 @@
# number
{
- "$schema": "https://vega.github.io/schema/vega-lite/v5.17.0.json",
+ "$schema": "https://vega.github.io/schema/vega-lite/v5.20.1.json",
"config": {
"view": {
"continuousHeight": 300,
@@ -170,7 +170,7 @@
# string
{
- "$schema": "https://vega.github.io/schema/vega-lite/v5.17.0.json",
+ "$schema": "https://vega.github.io/schema/vega-lite/v5.20.1.json",
"config": {
"view": {
"continuousHeight": 300,
@@ -211,7 +211,7 @@
# string (limit to 10 items)
{
- "$schema": "https://vega.github.io/schema/vega-lite/v5.17.0.json",
+ "$schema": "https://vega.github.io/schema/vega-lite/v5.20.1.json",
"config": {
"view": {
"continuousHeight": 300,
@@ -289,7 +289,7 @@
# unknown
{
- "$schema": "https://vega.github.io/schema/vega-lite/v5.17.0.json",
+ "$schema": "https://vega.github.io/schema/vega-lite/v5.20.1.json",
"config": {
"view": {
"continuousHeight": 300,
diff --git a/tests/_data/snapshots/charts_json_bad_data.txt b/tests/_data/snapshots/charts_json_bad_data.txt
index c9aef7b517..930dcd26d8 100644
--- a/tests/_data/snapshots/charts_json_bad_data.txt
+++ b/tests/_data/snapshots/charts_json_bad_data.txt
@@ -1,5 +1,5 @@
{
- "$schema": "https://vega.github.io/schema/vega-lite/v5.17.0.json",
+ "$schema": "https://vega.github.io/schema/vega-lite/v5.20.1.json",
"config": {
"view": {
"continuousHeight": 300,
diff --git a/tests/_data/snapshots/column_preview_chart_spec.txt b/tests/_data/snapshots/column_preview_chart_spec.txt
index 9b7714be87..f097a489d2 100644
--- a/tests/_data/snapshots/column_preview_chart_spec.txt
+++ b/tests/_data/snapshots/column_preview_chart_spec.txt
@@ -1,5 +1,5 @@
{
- "$schema": "https://vega.github.io/schema/vega-lite/v5.17.0.json",
+ "$schema": "https://vega.github.io/schema/vega-lite/v5.20.1.json",
"config": {
"view": {
"continuousHeight": 300,
diff --git a/tests/_data/snapshots/column_preview_date_chart_spec.txt b/tests/_data/snapshots/column_preview_date_chart_spec.txt
index 934f9142a6..cdd7d93989 100644
--- a/tests/_data/snapshots/column_preview_date_chart_spec.txt
+++ b/tests/_data/snapshots/column_preview_date_chart_spec.txt
@@ -1,5 +1,5 @@
{
- "$schema": "https://vega.github.io/schema/vega-lite/v5.17.0.json",
+ "$schema": "https://vega.github.io/schema/vega-lite/v5.20.1.json",
"config": {
"view": {
"continuousHeight": 300,
diff --git a/tests/_runtime/test_runtime.py b/tests/_runtime/test_runtime.py
index c1ef0c9c17..fbb8375503 100644
--- a/tests/_runtime/test_runtime.py
+++ b/tests/_runtime/test_runtime.py
@@ -1015,6 +1015,19 @@ class TestExecution:
# Does not pollute globals, reverts back to 10
assert k.globals["z"] == 10
+ async def test_rename(
+ self, any_kernel: Kernel, exec_req: ExecReqProvider
+ ) -> None:
+ k = any_kernel
+ await k.run([er := exec_req.get("x = __file__")])
+ assert "pytest" in k.globals["x"]
+ await k.rename_file("foo")
+ if k.lazy():
+ assert "pytest" in k.globals["x"]
+ assert k.graph.get_stale() == set([er.cell_id])
+ await k.run([er])
+ assert k.globals["x"] == "foo"
+
class TestStrictExecution:
@staticmethod