fix(api): use proper Annotated pattern in audit_logs.py, remove experimental root test files

- Remove _db_dep singleton and its use as default value in function signatures
- Use DbSession = Annotated[Session, Depends(get_db)] directly (matches files.py pattern)
- Declare db: DbSession without a default (FastAPI DI provides the session)
- Delete 10 experimental test_*.py files left at repo root from B008 debugging

Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot]
2026-03-16 10:05:41 +00:00
parent be6023464a
commit b5ac98889c
11 changed files with 4 additions and 99 deletions
+4 -6
View File
@@ -20,16 +20,14 @@ logger = logging.getLogger(__name__)
router = APIRouter() router = APIRouter()
# Module-level dependency singleton to satisfy Ruff B008 while maintaining default values for manual calls (e.g. in decorators). DbSession = Annotated[Session, Depends(get_db)]
_db_dep = Depends(get_db)
DbSession = Annotated[Session, _db_dep]
@router.get("/audit-logs") @router.get("/audit-logs")
@require_login @require_login
async def list_audit_logs( async def list_audit_logs(
request: Request, request: Request,
db: DbSession = _db_dep, db: DbSession,
action: Annotated[str | None, Query(description="Filter by action (exact match)")] = None, action: Annotated[str | None, Query(description="Filter by action (exact match)")] = None,
user: Annotated[str | None, Query(description="Filter by username")] = None, user: Annotated[str | None, Query(description="Filter by username")] = None,
resource_type: Annotated[str | None, Query(description="Filter by resource type")] = None, resource_type: Annotated[str | None, Query(description="Filter by resource type")] = None,
@@ -75,7 +73,7 @@ async def list_audit_logs(
@require_login @require_login
async def list_distinct_actions( async def list_distinct_actions(
request: Request, request: Request,
db: DbSession = _db_dep, db: DbSession,
) -> list[str]: ) -> list[str]:
"""Return the distinct action values present in the audit log.""" """Return the distinct action values present in the audit log."""
from app.models import AuditLog from app.models import AuditLog
@@ -88,7 +86,7 @@ async def list_distinct_actions(
@require_login @require_login
async def list_distinct_users( async def list_distinct_users(
request: Request, request: Request,
db: DbSession = _db_dep, db: DbSession,
) -> list[str]: ) -> list[str]:
"""Return the distinct user values present in the audit log.""" """Return the distinct user values present in the audit log."""
from app.models import AuditLog from app.models import AuditLog
-7
View File
@@ -1,7 +0,0 @@
from typing import Annotated
def Query(default, **kwargs):
return default
def test_func(action: Annotated[str | None, Query(None, description="test")] = None):
pass
-7
View File
@@ -1,7 +0,0 @@
from typing import Annotated
def Query(default=None, **kwargs):
return default
def test_func(limit: Annotated[int, Query(50, ge=1)] = 50):
pass
-4
View File
@@ -1,4 +0,0 @@
from typing import Annotated
def Query(default=None, **kwargs): return default
def test_func(limit: Annotated[int, Query(50, ge=1)] = 50):
pass
-6
View File
@@ -1,6 +0,0 @@
def Depends(arg=None):
return arg
def get_db():
pass
def test_func(db=Depends(get_db)):
pass
-18
View File
@@ -1,18 +0,0 @@
from typing import Annotated
class Depends:
def __init__(self, dependency=None):
pass
def get_db():
pass
DbSession = Annotated[int, Depends(get_db)]
# This is what I want to use
def test_func_ok(db: DbSession = Depends()):
pass
# This is what Ruff should flag
def test_func_bad(db: int = Depends(get_db)):
pass
-14
View File
@@ -1,14 +0,0 @@
from typing import Annotated
class Depends:
def __init__(self, dependency=None):
pass
def get_db():
pass
DbSession = Annotated[int, Depends(get_db)]
# Cleanest Annotated pattern
def test_func_clean(db: DbSession):
pass
-16
View File
@@ -1,16 +0,0 @@
from typing import Annotated
def Query(default=None, **kwargs):
return default
def Depends(dependency=None):
return dependency
def get_db():
return None
def test_func(
db: Annotated[int, Depends(get_db)] = Depends(),
action: Annotated[str | None, Query(None, description="test")] = None
):
pass
-11
View File
@@ -1,11 +0,0 @@
from typing import Annotated
class Depends:
def __init__(self, dependency=None):
pass
def get_db():
pass
def test_func(db: Annotated[int, Depends(get_db)] = Depends()):
pass
-4
View File
@@ -1,4 +0,0 @@
from typing import Annotated
def Query(x=None, **kwargs): return x
def test_func(x: Annotated[str, Query(None, description="test")] = None):
pass
-6
View File
@@ -1,6 +0,0 @@
from typing import Annotated
def Depends(x): return x
def get_db(): return "db"
DbSession = Annotated[str, Depends(get_db)]
def test_func(db: DbSession = None):
pass