From 2e33ba7723e177ad82ceecf7704948c0336205ce Mon Sep 17 00:00:00 2001 From: Anish Sarkar <104695310+AnishSarkar22@users.noreply.github.com> Date: Thu, 25 Jun 2026 04:31:36 +0530 Subject: [PATCH] chore: fix linting --- surfsense_backend/app/routes/zero_context_routes.py | 12 +++++++----- .../app/services/public_chat_service.py | 3 --- surfsense_backend/app/utils/pat.py | 5 ++++- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/surfsense_backend/app/routes/zero_context_routes.py b/surfsense_backend/app/routes/zero_context_routes.py index 27d4d6ce0..0277883d8 100644 --- a/surfsense_backend/app/routes/zero_context_routes.py +++ b/surfsense_backend/app/routes/zero_context_routes.py @@ -1,7 +1,7 @@ """Zero sync authentication context routes.""" from fastapi import APIRouter, Depends -from pydantic import BaseModel +from pydantic import BaseModel, ConfigDict, Field from sqlalchemy.ext.asyncio import AsyncSession from app.auth.context import AuthContext @@ -13,8 +13,10 @@ router = APIRouter(prefix="/zero", tags=["zero"]) class ZeroContextResponse(BaseModel): - userId: str - allowedSpaceIds: list[int] + model_config = ConfigDict(populate_by_name=True) + + user_id: str = Field(alias="userId") + allowed_space_ids: list[int] = Field(alias="allowedSpaceIds") @router.get("/context", response_model=ZeroContextResponse) @@ -24,6 +26,6 @@ async def get_zero_context( ) -> ZeroContextResponse: allowed_space_ids = await get_allowed_read_space_ids(session, auth) return ZeroContextResponse( - userId=str(auth.user.id), - allowedSpaceIds=allowed_space_ids, + user_id=str(auth.user.id), + allowed_space_ids=allowed_space_ids, ) diff --git a/surfsense_backend/app/services/public_chat_service.py b/surfsense_backend/app/services/public_chat_service.py index 0df69de09..11c57e969 100644 --- a/surfsense_backend/app/services/public_chat_service.py +++ b/surfsense_backend/app/services/public_chat_service.py @@ -435,7 +435,6 @@ async def list_snapshots_for_thread( thread_id: int, auth: AuthContext, ) -> list[dict]: - user = auth.user """List all public snapshots for a thread.""" from app.config import config @@ -482,7 +481,6 @@ async def list_snapshots_for_search_space( search_space_id: int, auth: AuthContext, ) -> list[dict]: - user = auth.user """List all public snapshots for a search space.""" from app.config import config @@ -540,7 +538,6 @@ async def delete_snapshot( snapshot_id: int, auth: AuthContext, ) -> bool: - user = auth.user """Delete a specific snapshot. Only thread owner can delete.""" # Get snapshot with thread result = await session.execute( diff --git a/surfsense_backend/app/utils/pat.py b/surfsense_backend/app/utils/pat.py index 46e3d4d08..e4b13d480 100644 --- a/surfsense_backend/app/utils/pat.py +++ b/surfsense_backend/app/utils/pat.py @@ -18,6 +18,7 @@ logger = logging.getLogger(__name__) PAT_PREFIX = "ss_pat_" PAT_TOKEN_BYTES = 32 LAST_USED_THROTTLE = timedelta(minutes=10) +_last_used_tasks: set[asyncio.Task[None]] = set() def generate_pat() -> str: @@ -70,4 +71,6 @@ def maybe_touch_last_used(pat: PersonalAccessToken) -> None: if last_used_at is not None and now - last_used_at < LAST_USED_THROTTLE: return - asyncio.create_task(_touch_last_used(pat.id)) + task = asyncio.create_task(_touch_last_used(pat.id)) + _last_used_tasks.add(task) + task.add_done_callback(_last_used_tasks.discard)