: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(convex): explain a deploy key from a different deployment (#111659)
Tom Owers24f8e9b1c8f4
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/convex/convex.py b/products/warehouse_sources/backend/temporal/data_imports/sources/convex/convex.pyindex 4f1819cdc599..f4b0d57d5644 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/convex/convex.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/convex/convex.py@@ -49,6 +49,8 @@ class ConvexResumeConfig:_CONVEX_CLOUD_HOST_RE = re.compile(r"^[a-z0-9][a-z0-9-]*(?:\.[a-z0-9][a-z0-9-]*)?\.convex\.cloud$")+# Production and development deploy keys name their deployment, e.g. "prod:swift-lemur-123|...".+_DEPLOY_KEY_DEPLOYMENT_RE = re.compile(r"^(?:prod|dev):([a-z0-9][a-z0-9-]*)\|")class InvalidDeployUrlError(Exception):@@ -124,6 +126,14 @@ def validate_deploy_key(deploy_key: str) -> str:return deploy_key+def deploy_key_targets_other_deployment(clean_url: str, deploy_key: str) -> bool:+ match = _DEPLOY_KEY_DEPLOYMENT_RE.match(deploy_key)+ if match is None:+ return False+ deployment_name = (urlparse(clean_url).hostname or "").split(".")[0]+ return match.group(1) != deployment_name++def _headers(deploy_key: str) -> dict[str, str]:return {"Authorization": f"Convex {validate_deploy_key(deploy_key)}",@@ -422,7 +432,16 @@ def validate_credentials(deploy_url: str, deploy_key: str) -> tuple[bool, str |except HTTPError as e:if e.response is not None:if e.response.status_code in (401, 403):- return False, "Invalid deploy key. Check your Convex deploy key and try again."+ if deploy_key_targets_other_deployment(clean_url, deploy_key):+ return (+ False,+ "Your deploy key belongs to a different Convex deployment than your deployment URL. "+ "Copy both from the same deployment's settings, then reconnect.",+ )+ return (+ False,+ "Convex rejected your deploy key. Copy a new deploy key from your Convex dashboard, then reconnect.",+ )# Any other status falls through to a generic message. Keep the raw error# (which embeds the deployment URL) out of what the user sees.detail = f" (HTTP {e.response.status_code})" if e.response is not None else ""diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/convex/tests/test_convex.py b/products/warehouse_sources/backend/temporal/data_imports/sources/convex/tests/test_convex.pyindex 5eedd85d9a38..db17e61a2d50 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/convex/tests/test_convex.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/convex/tests/test_convex.py@@ -152,6 +152,28 @@ class TestValidateDeployUrl:assert "convex.cloud" not in errassert "400" in err+ @parameterized.expand(+ [+ ("same_deployment", "prod:swift-lemur-123|abc", "Convex rejected your deploy key."),+ ("unnamed_key", "abc123", "Convex rejected your deploy key."),+ ("dev_key_for_prod_url", "dev:quiet-otter-456|abc", "belongs to a different Convex deployment"),+ ("key_for_other_project", "prod:quiet-otter-456|abc", "belongs to a different Convex deployment"),+ ]+ )+ @patch("products.warehouse_sources.backend.temporal.data_imports.sources.convex.convex.make_tracked_session")+ def test_validate_credentials_explains_a_rejected_deploy_key(self, _name, deploy_key, expected, mock_get):+ response = Mock()+ response.raise_for_status.side_effect = HTTPError(response=Mock(status_code=401))+ mock_get.return_value.get.return_value = response++ ok, err = validate_credentials("https://swift-lemur-123.eu-west-1.convex.cloud", deploy_key)++ assert not ok+ assert err is not None+ assert expected in err+ assert "swift-lemur-123" not in err+ assert "quiet-otter-456" not in err+class TestValidateDeployKey:@parameterized.expand(