Skip to content

Commit

Permalink
squashme: address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
olevski committed Oct 29, 2024
1 parent 93899c7 commit ffb3570
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
29 changes: 16 additions & 13 deletions components/renku_data_services/data_connectors/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from cryptography.hazmat.primitives.asymmetric import rsa
from sqlalchemy import Select, delete, func, or_, select
from sqlalchemy.ext.asyncio import AsyncSession
from sqlalchemy.orm import selectinload
from ulid import ULID

from renku_data_services import base_models, errors
Expand Down Expand Up @@ -501,19 +502,21 @@ async def get_data_connectors_with_secrets(
)

async with self.session_maker() as session:
stmt = select(schemas.DataConnectorORM).where(
schemas.DataConnectorORM.project_links.any(
schemas.DataConnectorToProjectLinkORM.project_id == project_id
),
or_(
# Data connectors with secrets for the specific user
schemas.DataConnectorORM.secrets.any(
schemas.DataConnectorSecretORM.user_id == user.id,
),
# Data connectors without any secrets
# See: https://docs.sqlalchemy.org/en/20/orm/queryguide/select.html#exists-forms-has-any
~schemas.DataConnectorORM.secrets.any(),
),
stmt = (
select(schemas.DataConnectorORM)
.where(
schemas.DataConnectorORM.project_links.any(
schemas.DataConnectorToProjectLinkORM.project_id == project_id
)
)
# Use the DB to filter the secrets returned by the relationship
# See: https://docs.sqlalchemy.org/en/20/orm/queryguide/relationships.html#adding-criteria-to-loader-options
.options(
selectinload(
schemas.DataConnectorSecretORM.secrets.and_(schemas.DataConnectorSecretORM.user_id == user.id)
)
)
.execution_options(populate_existing=True)
)
results = await session.stream_scalars(stmt)
async for dc in results:
Expand Down
2 changes: 1 addition & 1 deletion components/renku_data_services/data_connectors/orm.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class DataConnectorORM(BaseORM):
onupdate=func.now(),
nullable=False,
)
secrets: Mapped[list["DataConnectorSecretORM"]] = relationship(init=False, viewonly=True, lazy="selectin")
secrets: Mapped[list["DataConnectorSecretORM"]] = relationship(init=False, viewonly=True)
project_links: Mapped[list["DataConnectorToProjectLinkORM"]] = relationship(init=False, viewonly=True)

def dump(self) -> models.DataConnector:
Expand Down

0 comments on commit ffb3570

Please sign in to comment.