From 2b75c4e6d309ad858ddb2cb1258ddfffeb8d121a Mon Sep 17 00:00:00 2001 From: "DESKTOP-RTLN3BA\\$punk" Date: Mon, 9 Feb 2026 14:14:46 -0800 Subject: [PATCH] chore: linting --- .../agents/new_chat/tools/knowledge_base.py | 19 +++++++++---------- .../routes/search_source_connectors_routes.py | 14 +++++++------- .../app/tasks/celery_tasks/document_tasks.py | 2 +- 3 files changed, 17 insertions(+), 18 deletions(-) diff --git a/surfsense_backend/app/agents/new_chat/tools/knowledge_base.py b/surfsense_backend/app/agents/new_chat/tools/knowledge_base.py index 5f31b4f5c..fefd80f04 100644 --- a/surfsense_backend/app/agents/new_chat/tools/knowledge_base.py +++ b/surfsense_backend/app/agents/new_chat/tools/knowledge_base.py @@ -413,16 +413,15 @@ async def search_knowledge_base_async( kwargs["end_date"] = resolved_end_date try: - async with semaphore: - # Use isolated session per connector. Shared AsyncSession cannot safely - # run concurrent DB operations. - async with async_session_maker() as isolated_session: - isolated_connector_service = ConnectorService( - isolated_session, search_space_id - ) - connector_method = getattr(isolated_connector_service, method_name) - _, chunks = await connector_method(**kwargs) - return chunks + # Use isolated session per connector. Shared AsyncSession cannot safely + # run concurrent DB operations. + async with semaphore, async_session_maker() as isolated_session: + isolated_connector_service = ConnectorService( + isolated_session, search_space_id + ) + connector_method = getattr(isolated_connector_service, method_name) + _, chunks = await connector_method(**kwargs) + return chunks except Exception as e: print(f"Error searching connector {connector}: {e}") return [] diff --git a/surfsense_backend/app/routes/search_source_connectors_routes.py b/surfsense_backend/app/routes/search_source_connectors_routes.py index 02737c146..ba6877376 100644 --- a/surfsense_backend/app/routes/search_source_connectors_routes.py +++ b/surfsense_backend/app/routes/search_source_connectors_routes.py @@ -19,6 +19,7 @@ Non-OAuth connectors (BookStack, GitHub, etc.) are limited to one per search spa """ import logging +from contextlib import suppress from datetime import UTC, datetime, timedelta from typing import Any @@ -31,6 +32,7 @@ from sqlalchemy.exc import IntegrityError from sqlalchemy.ext.asyncio import AsyncSession from sqlalchemy.future import select +from app.config import config from app.connectors.github_connector import GitHubConnector from app.db import ( Permission, @@ -69,16 +71,16 @@ from app.tasks.connector_indexers import ( index_slack_messages, ) from app.users import current_active_user +from app.utils.indexing_locks import ( + acquire_connector_indexing_lock, + release_connector_indexing_lock, +) from app.utils.periodic_scheduler import ( create_periodic_schedule, delete_periodic_schedule, update_periodic_schedule, ) from app.utils.rbac import check_permission -from app.utils.indexing_locks import ( - acquire_connector_indexing_lock, - release_connector_indexing_lock, -) # Set up logging logger = logging.getLogger(__name__) @@ -1569,10 +1571,8 @@ async def _run_indexing_with_notifications( except Exception: pass # Ignore cleanup errors - key will expire anyway if connector_lock_acquired: - try: + with suppress(Exception): release_connector_indexing_lock(connector_id) - except Exception: - pass # Lock has TTL; safe to ignore cleanup failures async def run_notion_indexing_with_new_session( diff --git a/surfsense_backend/app/tasks/celery_tasks/document_tasks.py b/surfsense_backend/app/tasks/celery_tasks/document_tasks.py index 859b15018..3e60b5819 100644 --- a/surfsense_backend/app/tasks/celery_tasks/document_tasks.py +++ b/surfsense_backend/app/tasks/celery_tasks/document_tasks.py @@ -1102,4 +1102,4 @@ async def _process_circleback_meeting( if heartbeat_task: heartbeat_task.cancel() if notification: - _stop_heartbeat(notification.id) \ No newline at end of file + _stop_heartbeat(notification.id)