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-warehouse): reject non-object job_inputs on source update (#130211)

Tom Owersae613829b4b7
diff --git a/products/warehouse_sources/backend/presentation/views/external_data_source/source_setup.py b/products/warehouse_sources/backend/presentation/views/external_data_source/source_setup.py
index cdc088f28c49..c4a227943526 100644
--- a/products/warehouse_sources/backend/presentation/views/external_data_source/source_setup.py
+++ b/products/warehouse_sources/backend/presentation/views/external_data_source/source_setup.py
@@ -329,6 +329,11 @@ class ExternalDataSourceSerializers(UserAccessControlSerializerMixin, serializer
return self.preloaded_source_inputs[instance.id]
return SourceInputsStore.load(instance)
+ def validate_job_inputs(self, value: Any) -> dict[str, Any]:
+ if not isinstance(value, dict):
+ raise ValidationError("Must be an object.")
+ return value
+
def to_representation(self, instance):
representation = super().to_representation(instance)
diff --git a/products/warehouse_sources/backend/tests/api/test_external_data_source.py b/products/warehouse_sources/backend/tests/api/test_external_data_source.py
index efca0a0bbe96..2812c98bf722 100644
--- a/products/warehouse_sources/backend/tests/api/test_external_data_source.py
+++ b/products/warehouse_sources/backend/tests/api/test_external_data_source.py
@@ -93,6 +93,9 @@ from products.warehouse_sources.backend.presentation.views.external_data_source.
restore_declared_field_names,
strip_sensitive_from_dict,
)
+from products.warehouse_sources.backend.presentation.views.external_data_source.source_setup import (
+ ExternalDataSourceSerializers,
+)
from products.warehouse_sources.backend.presentation.views.external_data_source.viewset import ExternalDataSourceViewSet
from products.warehouse_sources.backend.temporal.data_imports import schema_flags
from products.warehouse_sources.backend.temporal.data_imports.sources import SourceRegistry
@@ -3666,6 +3669,20 @@ class TestExternalDataSource(APIBaseTest):
)
assert patch_response.status_code == 400
+ def test_update_with_json_encoded_string_job_inputs_returns_400(self):
+ source = self._create_external_data_source()
+
+ patch_response = self.client.patch(
+ f"/api/environments/{self.team.pk}/external_data_sources/{source.pk}/",
+ data={"job_inputs": json.dumps({"auth_method": {"selection": "api_key"}})},
+ format="json",
+ )
+
+ assert patch_response.status_code == 400, patch_response.json()
+ assert patch_response.json()["attr"] == "job_inputs"
+ source.refresh_from_db()
+ assert source.job_inputs == {"auth_method": {"selection": "api_key", "stripe_secret_key": "sk_test_123"}}
+
def test_get_external_data_source_with_schema(self):
source = self._create_external_data_source()
schema = self._create_external_data_schema(source.pk)
@@ -10330,6 +10347,27 @@ class TestCreateWebhook(APIBaseTest):
assert hog_function.inputs["source_id"]["value"] == str(source.pk)
+class TestExternalDataSourceJobInputsValidation(SimpleTestCase):
+ @parameterized.expand(
+ [
+ ("json_encoded_string", json.dumps({"auth_method": {"selection": "api_key"}})),
+ ("plain_string", "not-an-object"),
+ ("empty_string", ""),
+ ("list", [{"auth_method": {"selection": "api_key"}}]),
+ ("number", 1),
+ ("boolean", True),
+ ("null", None),
+ ]
+ )
+ def test_rejects_non_object(self, _name: str, job_inputs: Any):
+ with self.assertRaisesMessage(ValidationError, "Must be an object."):
+ ExternalDataSourceSerializers().validate_job_inputs(job_inputs)
+
+ @parameterized.expand([("empty", {}), ("populated", {"auth_method": {"selection": "api_key"}})])
+ def test_accepts_object(self, _name: str, job_inputs: dict[str, Any]):
+ assert ExternalDataSourceSerializers().validate_job_inputs(job_inputs) == job_inputs
+
+
class TestSensitiveFieldClassification(SimpleTestCase):
def test_classifies_password_fields_as_sensitive(self):
fields: list[FieldType] = [