From 4f4d823f1c3e728efbf1f40962491e078ba044ca Mon Sep 17 00:00:00 2001 From: santhreal <64453045+santhreal@users.noreply.github.com> Date: Fri, 17 Jul 2026 22:37:44 -0700 Subject: [PATCH] fix: allow recipes.jsonsplit to pass through NULL values Table.convert with jsonsplit raised OperationalError on NULL cells because None.split was called. Match parsedate and return None unchanged. --- sqlite_utils/recipes.py | 6 ++++-- tests/test_recipes.py | 2 ++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/sqlite_utils/recipes.py b/sqlite_utils/recipes.py index 55b55a4..08f3602 100644 --- a/sqlite_utils/recipes.py +++ b/sqlite_utils/recipes.py @@ -68,9 +68,11 @@ def parsedatetime( def jsonsplit( - value: str, delimiter: str = ",", type: Callable[[str], object] = str -) -> str: + value: Optional[str], delimiter: str = ",", type: Callable[[str], object] = str +) -> Optional[str]: """ Convert a string like a,b,c into a JSON array ["a", "b", "c"] """ + if value is None: + return value return json.dumps([type(s.strip()) for s in value.split(delimiter)]) diff --git a/tests/test_recipes.py b/tests/test_recipes.py index a7c7ef7..cf4655d 100644 --- a/tests/test_recipes.py +++ b/tests/test_recipes.py @@ -101,6 +101,7 @@ def test_jsonsplit(fresh_db, delimiter): [ {"id": 1, "tags": (delimiter or ",").join(["foo", "bar"])}, {"id": 2, "tags": (delimiter or ",").join(["bar", "baz"])}, + {"id": 3, "tags": None}, ], pk="id", ) @@ -116,6 +117,7 @@ def test_jsonsplit(fresh_db, delimiter): assert list(fresh_db["example"].rows) == [ {"id": 1, "tags": '["foo", "bar"]'}, {"id": 2, "tags": '["bar", "baz"]'}, + {"id": 3, "tags": None}, ]