diff --git a/backend/app/services/download_service.py b/backend/app/services/download_service.py index 2a8778a..b62dcd0 100644 --- a/backend/app/services/download_service.py +++ b/backend/app/services/download_service.py @@ -20,7 +20,8 @@ from typing import Any from sqlalchemy import select from sqlalchemy.ext.asyncio import AsyncSession -from sqlalchemy.orm import Session as SyncSession, joinedload +from sqlalchemy.orm import Session as SyncSession +from sqlalchemy.orm import joinedload from ..models import Artist, DownloadEvent, Source from .credential_service import CredentialService @@ -217,7 +218,10 @@ class DownloadService: if path_str in (dl_result.quarantined_paths or []): continue path = Path(path_str) - if not path.exists(): + # Sync stdlib filesystem ops are intentional here: this orchestrator + # runs under `asyncio.run` inside a Celery task — no other awaitables + # compete for the loop. ASYNC240 suppressed below. + if not path.exists(): # noqa: ASYNC240 continue def _attach(p=path): @@ -230,7 +234,7 @@ class DownloadService: if result.status in ("imported", "superseded"): import_summary["attached"] += 1 try: - bytes_downloaded += path.stat().st_size + bytes_downloaded += path.stat().st_size # noqa: ASYNC240 except OSError: pass elif result.status == "skipped" and result.skip_reason and result.skip_reason.value in ( @@ -238,7 +242,7 @@ class DownloadService: ): import_summary["skipped"] += 1 try: - path.unlink(missing_ok=True) + path.unlink(missing_ok=True) # noqa: ASYNC240 except OSError: pass else: diff --git a/backend/app/services/file_validator.py b/backend/app/services/file_validator.py index 791b142..ca6e40f 100644 --- a/backend/app/services/file_validator.py +++ b/backend/app/services/file_validator.py @@ -14,7 +14,6 @@ from __future__ import annotations from dataclasses import dataclass from pathlib import Path - JPEG_HEAD = b"\xff\xd8\xff" JPEG_TAIL = b"\xff\xd9" diff --git a/backend/app/services/gallery_dl.py b/backend/app/services/gallery_dl.py index eb37a2f..5e9b17f 100644 --- a/backend/app/services/gallery_dl.py +++ b/backend/app/services/gallery_dl.py @@ -19,7 +19,7 @@ import tempfile import time from dataclasses import dataclass, field from datetime import UTC, datetime -from enum import Enum +from enum import StrEnum from pathlib import Path from .file_validator import is_validatable, validate_file @@ -27,7 +27,7 @@ from .file_validator import is_validatable, validate_file log = logging.getLogger(__name__) -class ErrorType(str, Enum): +class ErrorType(StrEnum): AUTH_ERROR = "auth_error" RATE_LIMITED = "rate_limited" NOT_FOUND = "not_found" @@ -655,6 +655,6 @@ class GalleryDLService: ) finally: try: - Path(temp_config_path).unlink() + Path(temp_config_path).unlink() # noqa: ASYNC240 except Exception: pass