From 264510d3d73c2864ce08cf42d8016512f994f22f Mon Sep 17 00:00:00 2001 From: KooshaPari Date: Sat, 12 Sep 2026 23:24:43 -0700 Subject: [PATCH] fix: treat set/frozenset as JSON-storable types in types_for_column_types --- sqlite_utils/utils.py | 4 ++-- tests/test_utils.py | 9 +++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/sqlite_utils/utils.py b/sqlite_utils/utils.py index ee6695b55..a533bd89a 100644 --- a/sqlite_utils/utils.py +++ b/sqlite_utils/utils.py @@ -150,9 +150,9 @@ def types_for_column_types( t = str elif len(types) == 1: t = next(iter(types)) - # But if it's a subclass of list / tuple / dict, use str + # But if it's a subclass of list / tuple / dict / set, use str # instead as we will be storing it as JSON in the table - for superclass in (list, tuple, dict): + for superclass in (list, tuple, dict, set, frozenset): if issubclass(t, superclass): t = str elif {int, bool}.issuperset(types): diff --git a/tests/test_utils.py b/tests/test_utils.py index 360a4436a..1f3018534 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -102,3 +102,12 @@ def test_flatten(input, expected): ) def test_dedupe_keys(input, expected): assert utils.dedupe_keys(input) == expected + + +def test_types_for_column_types_set_maps_to_str(): + """set and frozenset should be mapped to str for JSON storage, like list/tuple/dict""" + result = utils.types_for_column_types({"tags": {set}}) + assert result["tags"] is str + + result = utils.types_for_column_types({"tags": {frozenset}}) + assert result["tags"] is str