connections duplicate bug

This commit is contained in:
phact 2025-09-09 13:16:14 -04:00
parent 97a17c77d7
commit d34a3c81f2

View file

@ -45,28 +45,63 @@ async def connector_sync(request: Request, connector_service, session_manager):
status_code=404, status_code=404,
) )
# Start sync tasks for all active connections # Find the first connection that actually works
task_ids = [] working_connection = None
for connection in active_connections: for connection in active_connections:
logger.debug( logger.debug(
"About to call sync_connector_files for connection", "Testing connection authentication",
connection_id=connection.connection_id, connection_id=connection.connection_id,
) )
if selected_files: try:
task_id = await connector_service.sync_specific_files( # Get the connector instance and test authentication
connection.connection_id, connector = await connector_service.get_connector(connection.connection_id)
user.user_id, if connector and await connector.authenticate():
selected_files, working_connection = connection
jwt_token=jwt_token, logger.debug(
"Found working connection",
connection_id=connection.connection_id,
)
break
else:
logger.debug(
"Connection authentication failed",
connection_id=connection.connection_id,
)
except Exception as e:
logger.debug(
"Connection validation failed",
connection_id=connection.connection_id,
error=str(e),
) )
else: continue
task_id = await connector_service.sync_connector_files(
connection.connection_id, if not working_connection:
user.user_id, return JSONResponse(
max_files, {"error": f"No working {connector_type} connections found"},
jwt_token=jwt_token, status_code=404,
) )
task_ids.append(task_id)
# Use the working connection
logger.debug(
"Starting sync with working connection",
connection_id=working_connection.connection_id,
)
if selected_files:
task_id = await connector_service.sync_specific_files(
working_connection.connection_id,
user.user_id,
selected_files,
jwt_token=jwt_token,
)
else:
task_id = await connector_service.sync_connector_files(
working_connection.connection_id,
user.user_id,
max_files,
jwt_token=jwt_token,
)
task_ids = [task_id]
return JSONResponse( return JSONResponse(
{ {
"task_ids": task_ids, "task_ids": task_ids,