: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(clickup): reject a pasted workspace url with a clear message (#111729)
Tom Owersb76942c54e3b
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/clickup/clickup.py b/products/warehouse_sources/backend/temporal/data_imports/sources/clickup/clickup.pyindex ac845deb5ddd..280fab2ccaa5 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/clickup/clickup.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/clickup/clickup.py@@ -618,6 +618,12 @@ def clickup_source(def validate_credentials(api_key: str, workspace_id: str | None) -> tuple[bool, str | None]:"""Confirm the token is genuine and (when provided) can see the configured workspace."""+ if workspace_id and not workspace_id.isdigit():+ return False, (+ "Your workspace ID is the number right after app.clickup.com/ in your ClickUp URL. "+ "Enter only that number, not the full URL."+ )+try:response = make_tracked_session(redact_values=(api_key,)).get(f"{CLICKUP_BASE_URL}/team", headers=_get_headers(api_key), timeout=10@@ -626,13 +632,19 @@ def validate_credentials(api_key: str, workspace_id: str | None) -> tuple[bool,return False, str(e)if response.status_code == 401:- return False, "Invalid ClickUp API token"+ return False, (+ "Your ClickUp API token is invalid or expired. Generate a new token in ClickUp under "+ "Settings → Apps, then reconnect."+ )if not response.ok:return False, f"ClickUp API error: {response.status_code} {response.text}"if workspace_id:teams = response.json().get("teams", [])if not any(str(team.get("id")) == str(workspace_id) for team in teams):- return False, f"Workspace '{workspace_id}' is not accessible with this token"+ return False, (+ "Your ClickUp API token can't access this workspace. Check the workspace ID, or use "+ "a token from a member of that workspace."+ )return True, Nonediff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/clickup/tests/test_clickup.py b/products/warehouse_sources/backend/temporal/data_imports/sources/clickup/tests/test_clickup.pyindex 5665e4f9961e..ce5ecf61c626 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/clickup/tests/test_clickup.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/clickup/tests/test_clickup.py@@ -158,7 +158,22 @@ class TestValidateCredentials:bad, message = validate_credentials("pk_token", workspace_id="404")assert bad is False- assert message is not None and "404" in message+ assert message is not None and "can't access this workspace" in message++ @pytest.mark.parametrize(+ "workspace_id",+ ["https://app.clickup.com/9/settings/team/9/general", "app.clickup.com/9/home"],+ )+ @mock.patch(CLICKUP_SESSION_PATCH)+ def test_workspace_url_is_rejected_before_calling_clickup(+ self, mock_session: mock.MagicMock, workspace_id: str+ ) -> None:+ valid, message = validate_credentials("pk_token", workspace_id=workspace_id)++ assert valid is False+ assert message is not None and "Enter only that number" in message+ assert workspace_id not in message+ mock_session.return_value.get.assert_not_called()@mock.patch(CLICKUP_SESSION_PATCH)def test_request_exception_returns_error(self, mock_session: mock.MagicMock) -> None: