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(cdp): fall back to the schema default for an omitted required input (#86586)

Xander492f3b2bb490
diff --git a/posthog/cdp/test/test_validation.py b/posthog/cdp/test/test_validation.py
index d224264b3e09..021bfa9c10ba 100644
--- a/posthog/cdp/test/test_validation.py
+++ b/posthog/cdp/test/test_validation.py
@@ -222,6 +222,24 @@ class TestHogFunctionValidation(ClickhouseTestMixin, APIBaseTest, QueryMatchingT
},
}
+ def test_omitted_required_input_falls_back_to_the_schema_default(self):
+ schema = [
+ {"key": "url", "type": "string", "label": "Webhook URL", "required": True},
+ {"key": "method", "type": "string", "label": "HTTP Method", "required": True, "default": "POST"},
+ ]
+
+ inputs = validate_inputs(schema, {"url": {"value": "https://example.com"}})
+
+ assert inputs["method"]["value"] == "POST"
+
+ def test_explicitly_emptied_required_input_is_still_rejected(self):
+ schema = [{"key": "method", "type": "string", "label": "HTTP Method", "required": True, "default": "POST"}]
+
+ with pytest.raises(ValidationError) as e:
+ validate_inputs(schema, {"method": {"value": ""}})
+
+ assert "This field is required." in str(e.value)
+
def test_validate_inputs_creates_bytecode_for_html(self):
# NOTE: CSS block curly brackets must be escaped beforehand
html_with_css = '<html>\n<head>\n<style type="text/css">\n .css \\{\n width: 500px !important;\n }</style>\n</head>\n\n<body>\n <p>Hi {person.properties.email}</p>\n</body>\n</html>'
diff --git a/posthog/cdp/validation.py b/posthog/cdp/validation.py
index 6746cb352700..49bc8764d0f8 100644
--- a/posthog/cdp/validation.py
+++ b/posthog/cdp/validation.py
@@ -742,6 +742,11 @@ class InputsSerializer(serializers.DictField):
errors[key] = "No value is saved for this secret input. Enter the value again."
continue
+ if value == {} and schema.get("required") and schema.get("default") is not None:
+ # The destination editor pre-fills defaults from the template schema, but callers that
+ # build inputs by hand cannot, so a required input with a default would reject them.
+ value = {"value": schema["default"]}
+
self.context["schema"] = schema
# Propagate templating from schema to input item, if set