: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(custom): name blank builder fields in the create error (#109758)
Tom Owersfc85aa437c04
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/custom/source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/custom/source.pyindex 6a4e9040109a..356b1cd4daea 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/custom/source.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/custom/source.py@@ -474,6 +474,22 @@ def _render_error_location(loc: tuple[Any, ...]) -> str:return rendered+def _blank_builder_field_label(error: Any) -> str | None:+ """Name a blank required field the way the source builder labels it, e.g.+ ``("resources", 0, "endpoint", "path")`` -> ``table 1 path``."""+ if error["type"] != "string_too_short":+ return None+ loc = tuple(error["loc"])+ if loc == ("client", "base_url"):+ return "base URL"+ if len(loc) >= 3 and loc[0] == "resources" and isinstance(loc[1], int):+ if loc[2:] == ("name",):+ return f"table {loc[1] + 1} name"+ if loc[2:] == ("endpoint", "path"):+ return f"table {loc[1] + 1} path"+ return None++def _format_validation_errors(exc: ValidationError) -> str:"""Render Pydantic's validation errors as a single user-facing string.@@ -481,8 +497,15 @@ def _format_validation_errors(exc: ValidationError) -> str:have at least 1 character") read like internals to someone editing manifestJSON, so mirror the JSON path and swap the common messages for plainer English."""+ errors = exc.errors()+ # Blank builder fields are the common wizard failure, and the builder shows form labels+ # rather than manifest paths, so name the fields the way the form does.+ blank_labels = [_blank_builder_field_label(error) for error in errors]+ if errors and all(blank_labels):+ return f"These required fields are empty: {', '.join(cast(list[str], blank_labels))}. Fill them in, then try again."+messages: list[str] = []- for error in exc.errors():+ for error in errors:location = _render_error_location(error["loc"])message = _VALIDATION_MESSAGE_OVERRIDES.get(error["type"], error["msg"].removeprefix("Value error, "))messages.append(f"{location}: {message}" if location else message)diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/custom/test_custom_source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/custom/test_custom_source.pyindex b96412783838..31bf26b8245a 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/custom/test_custom_source.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/custom/test_custom_source.py@@ -122,16 +122,25 @@ class TestValidateManifest(SimpleTestCase):validate_manifest(manifest)assert expected_substring in str(ctx.exception)- def test_empty_required_strings_give_plain_message(self):- # Empty required fields used to surface pydantic's raw "String should have at- # least 1 character" with positional paths; assert the friendlier, JSON-mirroring form.- manifest = {"client": {"base_url": ""}, "resources": [{"name": "", "endpoint": {"path": ""}}]}+ @parameterized.expand(+ [+ (+ {"client": {"base_url": ""}, "resources": [{"name": "", "endpoint": {"path": ""}}]},+ "These required fields are empty: base URL, table 1 name, table 1 path. Fill them in, then try again.",+ ),+ (+ {+ "client": {"base_url": "https://x"},+ "resources": [{"name": "users", "endpoint": {"path": "/users"}}, {"name": "", "endpoint": {}}],+ },+ "resources[1].name: must not be empty; resources[1].endpoint.path: Field required",+ ),+ ]+ )+ def test_empty_required_strings_give_plain_message(self, manifest, expected_message):with self.assertRaises(ManifestValidationError) as ctx:validate_manifest(manifest)- message = str(ctx.exception)- assert "client.base_url: must not be empty" in message- assert "resources[0].name: must not be empty" in message- assert "resources[0].endpoint.path: must not be empty" in message+ assert str(ctx.exception) == expected_messagedef test_rejects_duplicate_resource_names(self):manifest = _minimal_manifest()