diff --git a/backend/danswer/auth/users.py b/backend/danswer/auth/users.py index 13a0902b8cc..aa5054983fa 100644 --- a/backend/danswer/auth/users.py +++ b/backend/danswer/auth/users.py @@ -49,6 +49,7 @@ from httpx_oauth.oauth2 import OAuth2Token from pydantic import BaseModel from sqlalchemy import select +from sqlalchemy import text from sqlalchemy.orm import attributes from sqlalchemy.orm import Session @@ -366,6 +367,10 @@ async def oauth_callback( } user = await self.user_db.create(user_dict) + + # Explicitly set the Postgres schema for this session to ensure + # OAuth account creation happens in the correct tenant schema + await db_session.execute(text(f'SET search_path = "{tenant_id}"')) user = await self.user_db.add_oauth_account( user, oauth_account_dict ) diff --git a/backend/danswer/configs/app_configs.py b/backend/danswer/configs/app_configs.py index 1e9e0099d8b..35b405b90b1 100644 --- a/backend/danswer/configs/app_configs.py +++ b/backend/danswer/configs/app_configs.py @@ -142,7 +142,7 @@ os.environ.get("POSTGRES_PASSWORD") or "password" ) POSTGRES_HOST = os.environ.get("POSTGRES_HOST") or "localhost" -POSTGRES_PORT = os.environ.get("POSTGRES_PORT") or "5432" +POSTGRES_PORT = os.environ.get("POSTGRES_PORT") or "5433" POSTGRES_DB = os.environ.get("POSTGRES_DB") or "postgres" POSTGRES_API_SERVER_POOL_SIZE = int( diff --git a/backend/danswer/db/auth.py b/backend/danswer/db/auth.py index 9eba3806df5..53fba1e52dc 100644 --- a/backend/danswer/db/auth.py +++ b/backend/danswer/db/auth.py @@ -57,7 +57,10 @@ async def get_user_count() -> int: # Need to override this because FastAPI Users doesn't give flexibility for backend field creation logic in OAuth flow class SQLAlchemyUserAdminDB(SQLAlchemyUserDatabase): - async def create(self, create_dict: Dict[str, Any]) -> UP: + async def create( + self, + create_dict: Dict[str, Any], + ) -> UP: user_count = await get_user_count() if user_count == 0 or create_dict["email"] in get_default_admin_user_emails(): create_dict["role"] = UserRole.ADMIN diff --git a/deployment/docker_compose/docker-compose.dev.yml b/deployment/docker_compose/docker-compose.dev.yml index 7b31689c8f3..1780772583e 100644 --- a/deployment/docker_compose/docker-compose.dev.yml +++ b/deployment/docker_compose/docker-compose.dev.yml @@ -315,7 +315,7 @@ services: - POSTGRES_USER=${POSTGRES_USER:-postgres} - POSTGRES_PASSWORD=${POSTGRES_PASSWORD:-password} ports: - - "5432:5432" + - "5433:5432" volumes: - db_volume:/var/lib/postgresql/data diff --git a/deployment/docker_compose/docker-compose.gpu-dev.yml b/deployment/docker_compose/docker-compose.gpu-dev.yml index a7e0a2afe97..ea40c2fef0a 100644 --- a/deployment/docker_compose/docker-compose.gpu-dev.yml +++ b/deployment/docker_compose/docker-compose.gpu-dev.yml @@ -313,7 +313,7 @@ services: - POSTGRES_USER=${POSTGRES_USER:-postgres} - POSTGRES_PASSWORD=${POSTGRES_PASSWORD:-password} ports: - - "5432:5432" + - "5433:5432" volumes: - db_volume:/var/lib/postgresql/data diff --git a/deployment/docker_compose/docker-compose.search-testing.yml b/deployment/docker_compose/docker-compose.search-testing.yml index fab950c064e..2afd54e029c 100644 --- a/deployment/docker_compose/docker-compose.search-testing.yml +++ b/deployment/docker_compose/docker-compose.search-testing.yml @@ -157,7 +157,7 @@ services: - POSTGRES_USER=${POSTGRES_USER:-postgres} - POSTGRES_PASSWORD=${POSTGRES_PASSWORD:-password} ports: - - "5432" + - "5433" volumes: - db_volume:/var/lib/postgresql/data