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: external cells should not capture vscode cells (#8401)
Dylan Madisetticb1bf0efaf65
diff --git a/marimo/_ast/cell_id.py b/marimo/_ast/cell_id.pyindex da4de76718..16f1db9204 100644--- a/marimo/_ast/cell_id.py+++ b/marimo/_ast/cell_id.py@@ -43,18 +43,30 @@ def external_prefix() -> str:def is_external_cell_id(cell_id: CellId_t) -> bool:"""- Check if cell_id is external (cloned app).+ Check if cell_id is from an embedded/nested app.- Uses the fact that external cell IDs are UUIDs.+ Detects only the embedded case: a UUID4 prefix (36 chars) followed by+ a non-empty cell ID suffix. Returns False for all other formats,+ including normal cell IDs and bare UUIDs (e.g. from VSCode).++ Cell ID formats:+ - "Hbol" -> normal cell (4 chars)+ - "<uuid>" -> VSCode cell (36 chars)+ - "<uuid>Hbol" -> embedded cell (37+ chars) ← detected here>>> is_external_cell_id("c9bf9e57-1685-4c89-bafb-ff5af830be8aHbol")True>>> is_external_cell_id("Hbol")False+ >>> is_external_cell_id("c9bf9e57-1685-4c89-bafb-ff5af830be8a")+ False"""- # UUIDs are 36 characters long, including hyphens- uuid_to_test = str(cell_id)[:36]+ cell_id_str = str(cell_id)+ # External IDs are UUID (36 chars) + suffix; bare UUIDs are not external+ if len(cell_id_str) <= 36:+ return False+ uuid_to_test = cell_id_str[:36]try:uuid_obj = UUID(uuid_to_test, version=4)except ValueError:diff --git a/tests/_ast/test_cell_manager.py b/tests/_ast/test_cell_manager.pyindex f3e400d1b1..f2f44ded0e 100644--- a/tests/_ast/test_cell_manager.py+++ b/tests/_ast/test_cell_manager.py@@ -3,6 +3,7 @@ from __future__ import annotationsimport pytestfrom marimo._ast.cell import Cell, CellConfig+from marimo._ast.cell_id import is_external_cell_idfrom marimo._ast.cell_manager import (CellManager,)@@ -186,6 +187,46 @@ class TestCellManager:assert len(ids) == 1000+class TestIsExternalCellId:+ """Test is_external_cell_id detection of embedded vs non-embedded IDs."""++ def test_normal_cell_id(self) -> None:+ assert is_external_cell_id(CellId_t("Hbol")) is False++ def test_bare_uuid_not_external(self) -> None:+ # VSCode cell IDs are bare UUIDs — should NOT be detected as external+ assert (+ is_external_cell_id(+ CellId_t("c9bf9e57-1685-4c89-bafb-ff5af830be8a")+ )+ is False+ )++ def test_embedded_cell_id(self) -> None:+ # UUID prefix + 4-char suffix = embedded+ assert (+ is_external_cell_id(+ CellId_t("c9bf9e57-1685-4c89-bafb-ff5af830be8aHbol")+ )+ is True+ )++ def test_embedded_setup_cell_id(self) -> None:+ # UUID prefix + "setup" suffix = embedded+ assert (+ is_external_cell_id(+ CellId_t("c9bf9e57-1685-4c89-bafb-ff5af830be8asetup")+ )+ is True+ )++ def test_empty_string(self) -> None:+ assert is_external_cell_id(CellId_t("")) is False++ def test_non_uuid_long_string(self) -> None:+ assert is_external_cell_id(CellId_t("x" * 40)) is False++class TestCellMatching:"""Test class for cell matching functionality."""