Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

fix(data-imports): reject non-list source config values with a clean error (#82904)

Tom Owersf5a3e47fe0cc
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/common/config.py b/products/warehouse_sources/backend/temporal/data_imports/sources/common/config.py
index 29f864bac3fc..ded119e18ee1 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/common/config.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/common/config.py
@@ -739,7 +739,7 @@ def str_to_optional_list(s: str | list[typing.Any] | None) -> list[str] | None:
return None
if isinstance(s, list):
values = [str(item).strip() for item in s]
- else:
+ elif isinstance(s, str):
stripped = s.strip()
if stripped == "":
return None
@@ -754,6 +754,11 @@ def str_to_optional_list(s: str | list[typing.Any] | None) -> list[str] | None:
values = [stripped]
else:
values = [item.strip() for item in stripped.split(",")]
+ else:
+ # A non-str/list value (e.g. a dict submitted for a multi-select field) has no list
+ # interpretation. Raise so `_convert_value` surfaces it as a clean validation error
+ # instead of an unhandled `AttributeError` from calling `.strip()` on it.
+ raise TypeError(f"expected a string, list, or None, got {type(s).__name__}")
values = [value for value in values if value]
return values or None
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/common/test/test_config.py b/products/warehouse_sources/backend/temporal/data_imports/sources/common/test/test_config.py
index bd2bd3dcacc6..eb28a37b0ff3 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/common/test/test_config.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/common/test/test_config.py
@@ -100,6 +100,15 @@ def test_str_to_optional_list(value, expected):
assert config.str_to_optional_list(value) == expected
[email protected]("value", [{"owner": "repo"}, {}, 5])
+def test_str_to_optional_list_rejects_unsupported_types(value):
+ """A non-str/list value (e.g. a dict submitted for a multi-select field) must raise a
+ `TypeError` that `_convert_value` can surface as a validation error, not an `AttributeError`
+ from calling `.strip()` on it."""
+ with pytest.raises(TypeError):
+ config.str_to_optional_list(value)
+
+
@pytest.mark.parametrize(
"value,expected",
[