From 1df47e61c8e57ab4d98469bbe7fd7c96884837bd Mon Sep 17 00:00:00 2001 From: doria <93405247+dr-frmr@users.noreply.github.com> Date: Mon, 3 Nov 2025 11:26:44 -0500 Subject: [PATCH] fix: remove list webhook db call (not needed, causes race condition) (#257) * fix: remove get_workspace call from list_webhooks (not necessary, causes race condition) * fix: remove old test --- src/crud/webhook.py | 5 +---- src/routers/webhooks.py | 2 +- src/webhooks/webhook_delivery.py | 2 +- tests/routes/test_webhooks.py | 7 ------- 4 files changed, 3 insertions(+), 13 deletions(-) diff --git a/src/crud/webhook.py b/src/crud/webhook.py index 1dcc29a8..65b05569 100644 --- a/src/crud/webhook.py +++ b/src/crud/webhook.py @@ -63,7 +63,7 @@ async def get_or_create_webhook_endpoint( async def list_webhook_endpoints( - db: AsyncSession, workspace_name: str + workspace_name: str, ) -> Select[tuple[models.WebhookEndpoint]]: """ List all webhook endpoints, optionally filtered by workspace. @@ -75,9 +75,6 @@ async def list_webhook_endpoints( Returns: List of webhook endpoints """ - # Verify workspace exists - await get_workspace(db, workspace_name) - return select(models.WebhookEndpoint).where( models.WebhookEndpoint.workspace_name == workspace_name ) diff --git a/src/routers/webhooks.py b/src/routers/webhooks.py index c6ae2017..aa3256c1 100644 --- a/src/routers/webhooks.py +++ b/src/routers/webhooks.py @@ -61,7 +61,7 @@ async def list_webhook_endpoints( if not jwt_params.ad and jwt_params.w is not None and jwt_params.w != workspace_id: raise AuthenticationException("Unauthorized access to resource") - stmt = await crud.list_webhook_endpoints(db, workspace_id) + stmt = await crud.list_webhook_endpoints(workspace_id) return await apaginate(db, stmt) diff --git a/src/webhooks/webhook_delivery.py b/src/webhooks/webhook_delivery.py index d9587009..316fdccc 100644 --- a/src/webhooks/webhook_delivery.py +++ b/src/webhooks/webhook_delivery.py @@ -82,7 +82,7 @@ async def _get_webhook_urls(db: AsyncSession, workspace_name: str) -> list[str]: Get all webhook endpoint URLs for a workspace. """ try: - endpoints = await list_webhook_endpoints(db, workspace_name) + endpoints = await list_webhook_endpoints(workspace_name) result = await db.execute(endpoints) return [endpoint.url for endpoint in result.scalars().all()] except Exception: diff --git a/tests/routes/test_webhooks.py b/tests/routes/test_webhooks.py index ed176473..8272dc9f 100644 --- a/tests/routes/test_webhooks.py +++ b/tests/routes/test_webhooks.py @@ -95,13 +95,6 @@ async def test_list_webhook_endpoints_with_data( assert "http://example2.com/webhook" in endpoint_urls -@pytest.mark.asyncio -async def test_list_webhook_endpoints_missing_workspace(client: TestClient): - response = client.get("/v2/workspaces/nonexistent-workspace/webhooks") - assert response.status_code == 404 - assert response.json() == {"detail": "Workspace nonexistent-workspace not found"} - - @pytest.mark.asyncio async def test_delete_webhook_endpoint( client: TestClient, sample_data: tuple[Workspace, Peer]