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: cache kwargs regression in 3480 (#4255)
Dylan Madisetti6b06d877c356
diff --git a/marimo/_save/save.py b/marimo/_save/save.pyindex eb856a4898..0536cf97fd 100644--- a/marimo/_save/save.py+++ b/marimo/_save/save.py@@ -190,9 +190,14 @@ class _cache_call:# Rewrite scoped args to prevent shadowed variablesarg_dict = {f"{ARG_PREFIX}{k}": v for (k, v) in zip(self._args, args)}- kwargs = {f"{ARG_PREFIX}{k}": v for (k, v) in kwargs.items()}+ kwargs_copy = {f"{ARG_PREFIX}{k}": v for (k, v) in kwargs.items()}# Capture the call case- scope = {**self.scope, **get_context().globals, **arg_dict, **kwargs}+ scope = {+ **self.scope,+ **get_context().globals,+ **arg_dict,+ **kwargs_copy,+ }assert self._loader is not None, UNEXPECTED_FAILURE_BOILERPLATEattempt = content_cache_attempt_from_base(self.base_block,diff --git a/tests/_save/test_cache.py b/tests/_save/test_cache.pyindex 9d81e994fa..8d7ea77feb 100644--- a/tests/_save/test_cache.py+++ b/tests/_save/test_cache.py@@ -1274,6 +1274,36 @@ class TestCacheDecorator:assert a != g("world")return+ @staticmethod+ def test_shadowed_kwargs(app) -> None:+ @app.cell+ def __():+ import marimo as mo++ return (mo,)++ @app.cell+ def __(mo):+ @mo.cache+ def g(value="hello"):+ return value++ return g++ @app.cell+ def __(g):+ assert g() == "hello"+ assert g(value="world") == "world"+ assert g(123) == 123+ assert g.hits == 0+ assert g(value="hello") == "hello"+ # Subjective whether this hits+ # But add to test to capture behavior.+ assert g.hits == 0+ assert g() == "hello"+ assert g.hits == 1+ return+@staticmethoddef test_shadowed_state(app) -> None:@app.cell