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: remove none vals from being written to toml (#4373)
Shahmir Varqha540a62ee7726
diff --git a/marimo/_utils/config/config.py b/marimo/_utils/config/config.pyindex 8e8267c9da..60af4790be 100644--- a/marimo/_utils/config/config.py+++ b/marimo/_utils/config/config.py@@ -43,8 +43,13 @@ class ConfigReader:import tomlkit_maybe_create_directory(self.filepath)++ dict_data = asdict(data)+ # None values is not valid toml, so we remove them+ dict_data = {k: v for k, v in dict_data.items() if v is not None}+with open(self.filepath, "w") as file:- tomlkit.dump(asdict(data), file)+ tomlkit.dump(dict_data, file)@staticmethoddef _get_home_directory() -> str:diff --git a/tests/_utils/config/test_config_reader.py b/tests/_utils/config/test_config_reader.pyindex 317e809fbe..0f014db6af 100644--- a/tests/_utils/config/test_config_reader.py+++ b/tests/_utils/config/test_config_reader.py@@ -4,6 +4,7 @@ from __future__ import annotationsimport osfrom dataclasses import dataclassfrom tempfile import NamedTemporaryFile+from typing import Optionalfrom marimo._utils.config.config import ConfigReader@@ -12,6 +13,7 @@ from marimo._utils.config.config import ConfigReaderclass TestConfig:__test__ = Falsevalue: str+ nullable_value: Optional[str] = Nonedef test_read_toml_invalid_syntax() -> None:@@ -39,3 +41,29 @@ def test_read_toml_valid() -> None:assert result == TestConfig(value="test")os.unlink(f.name)+++def test_write_toml_valid() -> None:+ with NamedTemporaryFile(mode="w", suffix=".toml", delete=False) as f:+ config = ConfigReader(f.name)+ written = TestConfig(value="test", nullable_value="value")+ config.write_toml(written)++ fallback = TestConfig(value="fallback")+ result = config.read_toml(TestConfig, fallback=fallback)+ assert result == written++ os.unlink(f.name)+++def test_write_toml_invalid_values() -> None:+ with NamedTemporaryFile(mode="w", suffix=".toml", delete=False) as f:+ config = ConfigReader(f.name)+ # None is not valid toml+ config.write_toml(TestConfig(value="test", nullable_value=None))++ fallback = TestConfig(value="fallback")+ result = config.read_toml(TestConfig, fallback=fallback)+ assert result == TestConfig(value="test")++ os.unlink(f.name)