Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Unable to login and missing keypairs when a user does not have any project #1360

Draft
wants to merge 17 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changes/1360.fix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Enable to query Keypair graphene by handling cases of users who don't belong to any project.
17 changes: 8 additions & 9 deletions src/ai/backend/manager/models/keypair.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ def from_row(
user=row["user"],
ssh_public_key=row["ssh_public_key"],
concurrency_limit=0, # deprecated
projects=row["groups_name"],
projects=row["groups_name"] if "groups_name" in row.keys() else [],
)

async def resolve_num_queries(self, info: graphene.ResolveInfo) -> int:
Expand Down Expand Up @@ -329,15 +329,10 @@ async def load_count(
is_active: bool = None,
filter: str = None,
) -> int:
from .group import association_groups_users, groups
from .user import users

j = (
sa.join(keypairs, users, keypairs.c.user == users.c.uuid)
.join(association_groups_users, users.c.uuid == association_groups_users.c.user_id)
.join(groups, association_groups_users.c.group_id == groups.c.id)
)
query = sa.select([sa.func.count()]).select_from(j)
j = sa.join(keypairs, users, keypairs.c.user == users.c.uuid)
query = sa.select([sa.func.count(sa.distinct(keypairs.c.user_id))]).select_from(j)
if domain_name is not None:
query = query.where(users.c.domain_name == domain_name)
if email is not None:
Expand Down Expand Up @@ -369,7 +364,11 @@ async def load_slice(

j = (
sa.join(keypairs, users, keypairs.c.user == users.c.uuid)
.join(association_groups_users, users.c.uuid == association_groups_users.c.user_id)
.join(
association_groups_users,
users.c.uuid == association_groups_users.c.user_id,
isouter=True,
)
.join(groups, association_groups_users.c.group_id == groups.c.id)
)
query = (
Expand Down
8 changes: 7 additions & 1 deletion src/ai/backend/manager/models/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,4 +357,10 @@ def agg_to_str(column: sa.Column) -> sa.sql.functions.Function:


def agg_to_array(column: sa.Column) -> sa.sql.functions.Function:
return sa.func.array_agg(psql.aggregate_order_by(column, column.asc()))
return sa.case(
(
sa.func.array_agg(column) != [None],
sa.func.array_agg(psql.aggregate_order_by(column, column.asc())),
),
else_=[],
)