Skip to content

Commit bc5ab2c

Browse files
authored
Fix: correct db access (#307)
1 parent cd4c7bc commit bc5ab2c

2 files changed

Lines changed: 4 additions & 6 deletions

File tree

src/discord-cluster-manager/api/api_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ async def _run_submission(
139139
submission: SubmissionRequest, mode: SubmissionMode, backend: KernelBackend
140140
):
141141
try:
142-
req = prepare_submission(submission, backend.db)
142+
req = prepare_submission(submission, backend)
143143
except Exception as e:
144144
raise HTTPException(status_code=400, detail=str(e)) from e
145145

src/discord-cluster-manager/api/main.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import json
55
import os
66
import time
7-
from contextlib import contextmanager
87
from dataclasses import asdict
98
from typing import Annotated, Optional
109

@@ -66,14 +65,12 @@ async def kernel_bot_error_handler(req: Request, exc: KernelBotError):
6665
return JSONResponse(status_code=exc.http_code, content={"message": str(exc)})
6766

6867

69-
@contextmanager
7068
def get_db():
7169
"""Database context manager with guaranteed error handling"""
7270
if not backend_instance:
7371
raise HTTPException(status_code=500, detail="Bot instance not initialized")
7472

75-
with backend_instance.db as db:
76-
yield db
73+
return backend_instance.db
7774

7875

7976
async def validate_cli_header(
@@ -359,7 +356,8 @@ async def run_submission( # noqa: C901
359356
raise
360357
except Exception as e:
361358
raise HTTPException(
362-
status_code=500, detail=f"Internal server error while validating leaderboard/GPU: {e}"
359+
status_code=500,
360+
detail=f"Internal server error while validating leaderboard/GPU: {e}",
363361
) from e
364362

365363
try:

0 commit comments

Comments
 (0)