: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(data-imports): skip bucket check when botocore rejects the endpoint (#85099)
Tom Owers2d10a1839e3b
diff --git a/products/data_warehouse/backend/s3.py b/products/data_warehouse/backend/s3.pyindex bb0d16a15b8e..257b4b7d1e2b 100644--- a/products/data_warehouse/backend/s3.py+++ b/products/data_warehouse/backend/s3.py@@ -115,7 +115,20 @@ def get_size_of_folder(path: str) -> float:def ensure_bucket_exists(s3_url: str, s3_key: str, s3_secret: str, s3_endpoint: Optional[str] = None) -> None:- s3_client = boto3.client("s3", aws_access_key_id=s3_key, aws_secret_access_key=s3_secret, endpoint_url=s3_endpoint)+ try:+ s3_client = boto3.client(+ "s3", aws_access_key_id=s3_key, aws_secret_access_key=s3_secret, endpoint_url=s3_endpoint+ )+ except ValueError as e:+ # botocore refuses to build a client for endpoint hostnames it deems malformed (e.g. a+ # container service name containing an underscore), yet delta-rs's object store — which does+ # the pipeline's actual reads and writes — talks to the same endpoint fine. This bucket check+ # is a best-effort convenience for local/self-hosted setups where the bucket is provisioned+ # out of band, so skip it rather than abort the sync; the storage layer surfaces a real error+ # later if the bucket is genuinely absent.+ if "Invalid endpoint" in str(e):+ return+ raiseparsed = urlparse(s3_url)if parsed.scheme != "s3":diff --git a/products/data_warehouse/backend/tests/test_s3.py b/products/data_warehouse/backend/tests/test_s3.pyindex feaa70393f2e..88be67ce0fc4 100644--- a/products/data_warehouse/backend/tests/test_s3.py+++ b/products/data_warehouse/backend/tests/test_s3.py@@ -122,6 +122,21 @@ class TestEnsureBucketExists(SimpleTestCase):else:ensure_bucket_exists("s3://my-bucket", "key", "secret")+ @patch("products.data_warehouse.backend.s3.boto3.client")+ def test_skips_check_when_botocore_rejects_the_endpoint(self, mock_boto3_client) -> None:+ # delta-rs accepts endpoints botocore refuses to build a client for (e.g. a service host+ # with an underscore), so a rejected endpoint must not abort the sync at this pre-check.+ mock_boto3_client.side_effect = ValueError("Invalid endpoint: http://object_storage:19000")++ ensure_bucket_exists("s3://my-bucket", "key", "secret", "http://object_storage:19000")++ @patch("products.data_warehouse.backend.s3.boto3.client")+ def test_reraises_unrelated_value_errors(self, mock_boto3_client) -> None:+ mock_boto3_client.side_effect = ValueError("something else went wrong")++ with self.assertRaises(ValueError):+ ensure_bucket_exists("s3://my-bucket", "key", "secret")+@patch("products.data_warehouse.backend.s3.boto3.client")def test_reraises_non_404_head_bucket_errors(self, mock_boto3_client) -> None:s3_client = MagicMock()