From 66b7b8fce06c471cc3c58533bfd0c63dfef0305a Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 18 Nov 2025 22:36:19 +0000 Subject: [PATCH] Move imports to top of file per PEP 8 guidelines - Moved os, uuid, pathlib imports from inside loop to top of file - Moved celery task import to module level - Improves readability and avoids re-import overhead --- surfsense_backend/app/routes/documents_routes.py | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/surfsense_backend/app/routes/documents_routes.py b/surfsense_backend/app/routes/documents_routes.py index cb11faf80..8f5d59945 100644 --- a/surfsense_backend/app/routes/documents_routes.py +++ b/surfsense_backend/app/routes/documents_routes.py @@ -1,5 +1,8 @@ # Force asyncio to use standard event loop before unstructured imports import asyncio +import os +import uuid +from pathlib import Path from fastapi import APIRouter, Depends, Form, HTTPException, UploadFile from sqlalchemy.ext.asyncio import AsyncSession @@ -23,6 +26,7 @@ from app.schemas import ( ) from app.users import current_active_user from app.utils.check_ownership import check_ownership +from app.tasks.celery_tasks.document_tasks import process_file_upload_task try: asyncio.set_event_loop_policy(asyncio.DefaultEventLoopPolicy()) @@ -108,11 +112,6 @@ async def create_documents_file_upload( for file in files: try: - # Save file to persistent uploads directory - import os - import uuid - from pathlib import Path - # Create uploads directory if it doesn't exist uploads_dir = Path(os.getenv("UPLOADS_DIR", "./uploads")) uploads_dir.mkdir(parents=True, exist_ok=True) @@ -127,10 +126,6 @@ async def create_documents_file_upload( with open(temp_path, "wb") as f: f.write(content) - from app.tasks.celery_tasks.document_tasks import ( - process_file_upload_task, - ) - process_file_upload_task.delay( temp_path, file.filename, search_space_id, str(user.id) )