Merge pull request #721 from christianlouis/copilot/sub-pr-692
Fix audit_logs.py: proper Annotated/Depends pattern, remove debug artifacts
This commit is contained in:
@@ -20,16 +20,14 @@ logger = logging.getLogger(__name__)
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
# Module-level dependency singleton to satisfy Ruff B008 while maintaining default values for manual calls (e.g. in decorators).
|
||||
_db_dep = Depends(get_db)
|
||||
DbSession = Annotated[Session, _db_dep]
|
||||
DbSession = Annotated[Session, Depends(get_db)]
|
||||
|
||||
|
||||
@router.get("/audit-logs")
|
||||
@require_login
|
||||
async def list_audit_logs(
|
||||
request: Request,
|
||||
db: DbSession = _db_dep,
|
||||
db: DbSession,
|
||||
action: Annotated[str | None, Query(description="Filter by action (exact match)")] = None,
|
||||
user: Annotated[str | None, Query(description="Filter by username")] = None,
|
||||
resource_type: Annotated[str | None, Query(description="Filter by resource type")] = None,
|
||||
@@ -75,7 +73,7 @@ async def list_audit_logs(
|
||||
@require_login
|
||||
async def list_distinct_actions(
|
||||
request: Request,
|
||||
db: DbSession = _db_dep,
|
||||
db: DbSession,
|
||||
) -> list[str]:
|
||||
"""Return the distinct action values present in the audit log."""
|
||||
from app.models import AuditLog
|
||||
@@ -88,7 +86,7 @@ async def list_distinct_actions(
|
||||
@require_login
|
||||
async def list_distinct_users(
|
||||
request: Request,
|
||||
db: DbSession = _db_dep,
|
||||
db: DbSession,
|
||||
) -> list[str]:
|
||||
"""Return the distinct user values present in the audit log."""
|
||||
from app.models import AuditLog
|
||||
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -1,6 +0,0 @@
|
||||
def Depends(arg=None):
|
||||
return arg
|
||||
def get_db():
|
||||
pass
|
||||
def test_func(db=Depends(get_db)):
|
||||
pass
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
Reference in New Issue
Block a user