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): raise actionable error on missing required config field (#73393)

Tom Owers4dd99c2813f6
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 864804bfd898..fa0cac1725d4 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
@@ -329,7 +329,23 @@ def to_config(
else:
inputs[field.name] = _convert_value(convert, value, field.name)
- return config_cls(**inputs)
+ try:
+ return config_cls(**inputs)
+ except TypeError as e:
+ # Stored job inputs that don't supply a required (no-default) field make
+ # `config_cls(**inputs)` raise the opaque builtin
+ # `TypeError: X.__init__() missing 1 required positional argument: 'y'`, which is
+ # impossible to triage from error tracking. Re-raise naming the missing field(s) — only
+ # the field names, never their values, so no secret leaks. Kept a TypeError so the
+ # union-config recursion above still catches it and tries the remaining arms.
+ missing = [
+ f.name
+ for f in fields
+ if f.default is dataclasses.MISSING and f.default_factory is dataclasses.MISSING and f.name not in inputs
+ ]
+ if not missing:
+ raise
+ raise TypeError(f"Cannot build '{config_cls.__name__}': missing required field(s) {missing}") from e
def _resolve_field_type(field: dataclasses.Field[typing.Any], module_path: str) -> type:
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 2a1f38660562..7d569a3ebfca 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
@@ -578,6 +578,20 @@ def test_to_config_optional_config_does_not_retain_unparseable_dict():
assert cfg.auth is None
[email protected]("config_dict", [{}, {"unrelated_key": "value"}])
+def test_from_dict_missing_required_field_raises_clear_error(config_dict):
+ # Stored job inputs that don't supply a required (no-default) field used to surface the
+ # opaque builtin `TypeError: SourceConfig.__init__() missing 1 required positional argument:
+ # 'api_key'`, which is impossible to triage from error tracking. It must name the field
+ # instead, and must not leak the (absent) secret value.
+ @config.config
+ class SourceConfig(config.Config):
+ api_key: str
+
+ with pytest.raises(TypeError, match=r"Cannot build 'SourceConfig': missing required field\(s\) \['api_key'\]"):
+ SourceConfig.from_dict(config_dict)
+
+
@config.config
class _SecretFieldConfig(config.Config):
password: str | None = None