: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(batch-exports): stop echoing the host in the invalid-host error (#94326)
Jovan Sakovicfa458b4202d4
diff --git a/products/batch_exports/backend/api/batch_export.py b/products/batch_exports/backend/api/batch_export.pyindex 777c4fbe3d49..7202301dae76 100644--- a/products/batch_exports/backend/api/batch_export.py+++ b/products/batch_exports/backend/api/batch_export.py@@ -1138,6 +1138,9 @@ def is_local_dev_or_test() -> bool:return settings.DEBUG or settings.TEST+INVALID_HOST_MESSAGE = "Invalid host. Enter a hostname or IP address without credentials, scheme, or path."++def resolve_and_validate_host(host: str) -> None:"""Ensure provided host resolves to a non-internal IP."""if host == "localhost" and is_local_dev_or_test():@@ -1699,7 +1702,7 @@ class BatchExportSerializer(serializers.ModelSerializer):try:resolve_and_validate_host(host)except ValueError:- raise serializers.ValidationError(f"Invalid host: '{host}'")+ raise serializers.ValidationError(INVALID_HOST_MESSAGE)return destination_attrsdiff --git a/products/batch_exports/backend/tests/api/test_create_postgres.py b/products/batch_exports/backend/tests/api/test_create_postgres.pyindex dd59042463f7..e0011adc6e25 100644--- a/products/batch_exports/backend/tests/api/test_create_postgres.py+++ b/products/batch_exports/backend/tests/api/test_create_postgres.py@@ -7,6 +7,7 @@ from rest_framework import statusfrom posthog.models.integration import Integration+from products.batch_exports.backend.api.batch_export import INVALID_HOST_MESSAGEfrom products.batch_exports.backend.tests.api.operations import create_batch_exportpytestmark = [@@ -77,6 +78,7 @@ def test_creating_postgres_batch_export_using_integration(client: HttpClient, te"127.0.0.1","10.0.0.1","192.168.1.1",+ "postgres://alice:[email protected]/app",],)def test_creating_postgres_batch_export_validates_integration_host(@@ -110,7 +112,9 @@ def test_creating_postgres_batch_export_validates_integration_host(response = create_batch_export(client, team.pk, batch_export_data)assert response.status_code == status.HTTP_400_BAD_REQUEST, response.json()- assert f"Invalid host: '{host}'" in response.json()["detail"]+ assert response.json()["detail"] == INVALID_HOST_MESSAGE+ assert host not in response.content.decode()+ assert "hunter2" not in response.content.decode()def test_creating_postgres_batch_export_without_integration_is_rejected(diff --git a/products/batch_exports/backend/tests/api/test_create_redshift.py b/products/batch_exports/backend/tests/api/test_create_redshift.pyindex 81742cb6fb11..6ce357042194 100644--- a/products/batch_exports/backend/tests/api/test_create_redshift.py+++ b/products/batch_exports/backend/tests/api/test_create_redshift.py@@ -7,6 +7,7 @@ from rest_framework import statusfrom posthog.models.integration import Integration+from products.batch_exports.backend.api.batch_export import INVALID_HOST_MESSAGEfrom products.batch_exports.backend.tests.api.fixtures import create_organization, create_team, create_userfrom products.batch_exports.backend.tests.api.operations import create_batch_export, get_batch_export_ok@@ -208,6 +209,7 @@ def test_create_redshift_batch_export_rejects_invalid_authorization_type("10.0.0.1","169.254.0.0","localhost",+ "postgres://alice:[email protected]/app",],)def test_create_redshift_batch_export_fails_with_invalid_host(@@ -246,7 +248,9 @@ def test_create_redshift_batch_export_fails_with_invalid_host()assert response.status_code == status.HTTP_400_BAD_REQUEST, response.json()- assert f"Invalid host: '{host}'" in response.json()["detail"]+ assert response.json()["detail"] == INVALID_HOST_MESSAGE+ assert host not in response.content.decode()+ assert "hunter2" not in response.content.decode()def test_create_redshift_batch_export_with_aws_integration(