Skip to content

Commit b6d149c

Browse files
authored
fix: send 404 when a sessions is not found (#1234)
Closes #1209.
1 parent 516b84f commit b6d149c

2 files changed

Lines changed: 18 additions & 1 deletion

File tree

components/renku_data_services/notebooks/blueprints.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,9 @@ def get_one(self) -> BlueprintFactoryResponse:
115115
async def _handler(_: Request, user: AuthenticatedAPIUser | AnonymousAPIUser, session_id: str) -> HTTPResponse:
116116
session = await self.nb_config.k8s_v2_client.get_session(session_id, user.id)
117117
if session is None:
118-
raise errors.ValidationError(message=f"The session with ID {session_id} does not exist.", quiet=True)
118+
raise errors.MissingResourceError(
119+
message=f"The session with ID {session_id} does not exist.", quiet=True
120+
)
119121
return json(session.as_apispec().model_dump(exclude_none=True, mode="json"))
120122

121123
return "/sessions/<session_id>", ["GET"], _handler

test/bases/renku_data_services/data_api/test_notebooks.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,3 +303,18 @@ async def test_start_server(
303303
_, res = await sanic_client.delete(f"/api/data/sessions/{server_name}", headers=authenticated_user_headers)
304304

305305
assert res.status_code == 204, res.text
306+
307+
308+
@pytest.mark.xdist_group("sessions") # Needs to run on the same worker as the rest of the sessions tests
309+
@pytest.mark.sessions
310+
@pytest.mark.asyncio
311+
async def test_not_found_server(
312+
sanic_client: SanicASGITestClient,
313+
authenticated_user_headers: dict[str, str],
314+
notebooks_fixtures,
315+
):
316+
server_name = "unknown_server"
317+
318+
_, res = await sanic_client.get(f"/api/data/sessions/{server_name}", headers=authenticated_user_headers)
319+
320+
assert res.status_code == 404, res.text

0 commit comments

Comments
 (0)