: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(cdp): report all missing email input keys in one error (#78204)
Harley Alexander44c13a997af6
diff --git a/posthog/cdp/test/test_validation.py b/posthog/cdp/test/test_validation.pyindex 99aa3a280452..68859bfa65f4 100644--- a/posthog/cdp/test/test_validation.py+++ b/posthog/cdp/test/test_validation.py@@ -412,6 +412,35 @@ class TestHogFunctionValidation(ClickhouseTestMixin, APIBaseTest, QueryMatchingTvalidated = validate_inputs(inputs_schema, inputs)assert validated["field"]["value"] == "Hey {{ person.properties.name }}"+ @parameterized.expand(+ [+ (+ "single_missing_key_keeps_the_familiar_message",+ {"to": "[email protected]", "subject": "hi", "html": "<p>hi</p>"},+ "Missing value for 'from'.",+ ),+ (+ "multiple_missing_keys_reported_at_once",+ {"to": "[email protected]"},+ "Missing values for 'from', 'subject', either 'text' or 'html'.",+ ),+ (+ "body_alternatives_named_together",+ {"from": "[email protected]", "to": "[email protected]", "subject": "hi"},+ "Missing value for either 'text' or 'html'.",+ ),+ ]+ )+ def test_email_input_reports_all_missing_keys_in_one_error(self, _name, value, expected):+ # Email objects are typically authored programmatically; raising on the first absent+ # key forces a validate round trip per key, so every missing key is named at once.+ inputs_schema = [{"key": "email", "type": "native_email", "required": True}]+ inputs = {"email": {"value": value}}++ with pytest.raises(ValidationError) as ctx:+ validate_inputs(inputs_schema, inputs)+ assert expected in str(ctx.value.detail)+@parameterized.expand([("person", "{person?.id}"),diff --git a/posthog/cdp/validation.py b/posthog/cdp/validation.pyindex 84f63a07f2fd..96d3864e792b 100644--- a/posthog/cdp/validation.py+++ b/posthog/cdp/validation.py@@ -413,12 +413,14 @@ class InputsItemSerializer(serializers.Serializer):elif item_type == "email" or item_type == "native_email":if not isinstance(value, dict):raise serializers.ValidationError({"input": f"Value must be an email object."})- for key_ in ["from", "to", "subject"]:- if not value.get(key_):- raise serializers.ValidationError({"input": f"Missing value for '{key_}'."})-+ # Report every missing key in one error: these objects are typically authored+ # programmatically, and a one-at-a-time raise forces a round trip per missing key.+ missing = [f"'{key_}'" for key_ in ("from", "to", "subject") if not value.get(key_)]if not value.get("text") and not value.get("html"):- raise serializers.ValidationError({"input": f"Either 'text' or 'html' is required."})+ missing.append("either 'text' or 'html'")+ if missing:+ label = "value" if len(missing) == 1 else "values"+ raise serializers.ValidationError({"input": f"Missing {label} for {', '.join(missing)}."})elif item_type == "non_failure_status_codes":if not isinstance(value, list):raise serializers.ValidationError({"input": "Value must be a list of status codes."})