: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.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(data-imports): stop config parsing crashing on scalar nested field (#63327)
Tom Owers044da550ae46
diff --git a/posthog/temporal/data_imports/sources/common/test/test_config.py b/posthog/temporal/data_imports/sources/common/test/test_config.pyindex a702f6611623..5eb225820017 100644--- a/posthog/temporal/data_imports/sources/common/test/test_config.py+++ b/posthog/temporal/data_imports/sources/common/test/test_config.py@@ -152,6 +152,44 @@ def test_nested_to_config_with_nested_dict():assert cfg.d is True[email protected]("scalar_value", ["oauth", "api_key", None])+def test_nested_to_config_with_scalar_value_for_nested_key(scalar_value):+ """Test `config.to_config` when a nested-config field's key holds a scalar.++ Mirrors the auth-method payload shape where the selection field is sent flat+ (``{"auth_method": "oauth", ...}``) instead of nested. The scalar must not be+ treated as a nested mapping — doing so previously swallowed a ``TypeError`` and+ dropped the required field, crashing on instantiation. Parsing should instead+ fall through to flat resolution and pick up sibling flat fields.+ """++ @config.config+ class AuthMethod:+ selection: str = "api_key"+ secret_key: str | None = None++ @config.config+ class Source(config.Config):+ auth_method: AuthMethod+ account_id: str | None = None++ config_dict = {+ "auth_method": scalar_value,+ "secret_key": "rk_live_x",+ "account_id": "acct_xxx",+ }++ cfg = Source.from_dict(config_dict)++ assert isinstance(cfg.auth_method, AuthMethod)+ assert cfg.auth_method.secret_key == "rk_live_x"+ assert cfg.account_id == "acct_xxx"++ # validate_dict already accepts this shape, so from_dict must agree and not crash.+ is_valid, errors = Source.validate_dict(config_dict)+ assert is_valid, errors++def test_nested_to_config_with_flat_dict_default_prefix():"""Test `config.to_config` with a nested set of classes.