mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-06-08 20:25:19 +02:00
feat: merge new credentials with existing connector configurations to preserve user settings
This commit is contained in:
parent
9e29265a61
commit
2125c76841
2 changed files with 15 additions and 2 deletions
|
|
@ -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()
|
||||
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue