Skip to content

Commit f358840

Browse files
committed
modified lfx.deps.py and langflow.services.utils.py
1 parent 9f16e53 commit f358840

2 files changed

Lines changed: 13 additions & 6 deletions

File tree

src/backend/base/langflow/services/utils.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@
2222
if TYPE_CHECKING:
2323
from lfx.services.settings.manager import SettingsService
2424
from sqlmodel.ext.asyncio.session import AsyncSession
25-
``
2625

2726
async def get_or_create_super_user(session: AsyncSession, username, password, is_default):
2827
from langflow.services.database.models.user.model import User
2928

3029
stmt = select(User).where(User.username == username)
31-
result = await session.exec(stmt) user = result.first()
30+
result = await session.exec(stmt)
31+
user = result.first()
3232

3333
if user and user.is_superuser:
3434
return None # Superuser already exists
@@ -287,7 +287,7 @@ async def initialize_services(*, fix_migration: bool = False) -> None:
287287
await initialize_database(fix_migration=fix_migration)
288288
db_service = get_db_service(use_organisation=False)
289289
await db_service.initialize_alembic_log_file()
290-
async with session_scope() as session:
290+
async with session_scope(use_organisation=False) as session:
291291
settings_service = get_service(ServiceType.SETTINGS_SERVICE)
292292
await setup_superuser(settings_service, session)
293293
try:

src/lfx/src/lfx/services/deps.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
from lfx.services.schema import ServiceType
1111

1212
if TYPE_CHECKING:
13+
from collections.abc import AsyncGenerator
14+
from sqlmodel.ext.asyncio.session import AsyncSession
1315
from lfx.services.interfaces import (
1416
CacheServiceProtocol,
1517
ChatServiceProtocol,
@@ -52,10 +54,15 @@ def get_service(service_type: ServiceType, default=None):
5254
return None
5355

5456

55-
def get_db_service() -> DatabaseServiceProtocol | None:
57+
def get_db_service(*, use_organisation: bool = True) -> DatabaseServiceProtocol | None:
5658
"""Retrieves the database service instance."""
5759
from lfx.services.schema import ServiceType
5860

61+
from langflow.services.database.organisation import OrganizationService
62+
63+
if use_organisation and get_settings_service().auth_settings.CLERK_AUTH_ENABLED:
64+
return OrganizationService.get_db_service_for_request()
65+
5966
return get_service(ServiceType.DATABASE_SERVICE)
6067

6168

@@ -102,13 +109,13 @@ def get_tracing_service() -> TracingServiceProtocol | None:
102109

103110

104111
@asynccontextmanager
105-
async def session_scope():
112+
async def session_scope(*, use_organisation: bool = True) -> AsyncGenerator[AsyncSession, None]:
106113
"""Session scope context manager.
107114
108115
Returns a real session if database service is available, otherwise a NoopSession.
109116
This ensures code can always call session methods without None checking.
110117
"""
111-
db_service = get_db_service()
118+
db_service = get_db_service(use_organisation=use_organisation)
112119
if db_service is None or inspect.isabstract(type(db_service)):
113120
from lfx.services.session import NoopSession
114121

0 commit comments

Comments
 (0)