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: preview UI-bound variables from the notebook namespace (#11478)
Trevor Manz31e252df8e74
diff --git a/marimo/_runtime/runtime.py b/marimo/_runtime/runtime.pyindex f58ecb0bdf..0e56d3d1ce 100644--- a/marimo/_runtime/runtime.py+++ b/marimo/_runtime/runtime.py@@ -2170,10 +2170,12 @@ class Kernel:}variable_values: list[VariableValue] = []for name in bound_names:- # TODO update variable values even for namespaces? lenses? etc- variable_values.append(- create_variable_value(name=name, value=value)- )+ if name in self.globals:+ variable_values.append(+ create_variable_value(+ name=name, value=self.globals[name]+ )+ )try:# subtracting self.graph.definitions[name]: never rerun the# cell that created the namediff --git a/tests/_runtime/test_runtime.py b/tests/_runtime/test_runtime.pyindex c33c722e75..aa1a68936c 100644--- a/tests/_runtime/test_runtime.py+++ b/tests/_runtime/test_runtime.py@@ -29,6 +29,7 @@ from marimo._messaging.errors import (from marimo._messaging.notification import (CellNotification,VariablesNotification,+ VariableValuesNotification,)from marimo._messaging.serde import deserialize_kernel_messagefrom marimo._plugins.ui._core.ids import IDProvider@@ -302,6 +303,36 @@ class TestExecution:await k.run([er])assert k.globals["x"] == 6+ async def test_set_ui_element_value_previews_bound_names(+ self, mocked_kernel: MockedKernel, exec_req: ExecReqProvider+ ) -> None:+ k = mocked_kernel.k+ await k.run(+ [+ exec_req.get(code="import marimo as mo"),+ exec_req.get(+ code="array = mo.ui.array([mo.ui.slider(0, 10, value=1)])"+ ),+ ]+ )+ mocked_kernel.stream.messages.clear()++ await k.set_ui_element_value(+ UpdateUIElementCommand.from_ids_and_values(+ [(k.globals["array"][0]._id, 5)]+ ),+ notify_frontend=False,+ )++ [notification] = [+ m+ for m in mocked_kernel.stream.parsed_operations+ if isinstance(m, VariableValuesNotification)+ ]+ assert [(v.name, v.value) for v in notification.variables] == [+ ("array", "[5]")+ ]+async def test_set_ui_element_value_lensed_with_state(self, any_kernel: Kernel, exec_req: ExecReqProvider) -> None: