feat: merge new credentials with existing connector configurations to preserve user settings

This commit is contained in:
Anish Sarkar 2026-02-02 19:03:05 +05:30
parent 9e29265a61
commit 2125c76841
2 changed files with 15 additions and 2 deletions

View file

@ -127,7 +127,12 @@ async def get_valid_credentials(
)
creds_dict["_token_encrypted"] = True
connector.config = creds_dict
# IMPORTANT: Merge new credentials with existing config to preserve
# user settings like selected_folders, selected_files, indexing_options,
# folder_tokens, etc. that would otherwise be wiped on token refresh.
existing_config = connector.config.copy() if connector.config else {}
existing_config.update(creds_dict)
connector.config = existing_config
flag_modified(connector, "config")
await session.commit()

View file

@ -20,6 +20,7 @@ from pydantic import ValidationError
from sqlalchemy.exc import IntegrityError
from sqlalchemy.ext.asyncio import AsyncSession
from sqlalchemy.future import select
from sqlalchemy.orm.attributes import flag_modified
from app.config import config
from app.db import (
@ -330,10 +331,17 @@ async def composio_callback(
)
# Update existing connector with new connected_account_id
# IMPORTANT: Merge new credentials with existing config to preserve
# user settings like selected_folders, selected_files, indexing_options,
# drive_page_token, etc. that would otherwise be wiped on reconnection.
logger.info(
f"Updating existing Composio connector {existing_connector.id} with new connected_account_id {final_connected_account_id}"
)
existing_connector.config = connector_config
existing_config = existing_connector.config.copy() if existing_connector.config else {}
existing_config.update(connector_config)
existing_connector.config = existing_config
flag_modified(existing_connector, "config")
await session.commit()
await session.refresh(existing_connector)