<!-- .github/pull_request_template.md --> ## Description <!-- Provide a clear description of the changes in this PR --> ## DCO Affirmation I affirm that all code in every commit of this pull request conforms to the terms of the Topoteretes Developer Certificate of Origin. --------- Co-authored-by: Boris Arzentar <borisarzentar@gmail.com> Co-authored-by: Boris <boris@topoteretes.com>
21 lines
768 B
Python
21 lines
768 B
Python
import sqlalchemy.exc
|
|
from sqlalchemy import select
|
|
from uuid import UUID
|
|
|
|
from cognee.infrastructure.databases.relational import get_relational_engine
|
|
from cognee.modules.users.exceptions import TenantNotFoundError
|
|
from ...models.Tenant import Tenant
|
|
|
|
|
|
async def get_tenant(tenant_id: UUID):
|
|
db_engine = get_relational_engine()
|
|
|
|
async with db_engine.get_async_session() as session:
|
|
try:
|
|
result = await session.execute(select(Tenant).where(Tenant.id == tenant_id))
|
|
tenant = result.unique().scalar_one()
|
|
if not tenant:
|
|
raise TenantNotFoundError
|
|
return tenant
|
|
except sqlalchemy.exc.NoResultFound:
|
|
raise TenantNotFoundError(message=f"Could not find tenant: {tenant_id}")
|