-
Notifications
You must be signed in to change notification settings - Fork 153
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: Regression of outdated vfolder
GQL resolver
#3047
Open
jopemachine
wants to merge
17
commits into
main
Choose a base branch
from
fix/broken-vfolder-gql
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+98
−48
Open
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
80a0f4f
fix: Broken `vfolder` GQL
jopemachine 6477f3f
fix: Consider empty case
jopemachine 05abacd
chore: Add news fragment
jopemachine a325655
chore: Update error msg
jopemachine 7a2d260
refactor: Add Image batch loader function (#3048)
fregataa b04a820
chore: Allow kwargs only for batch-load function (#3037)
fregataa 8790946
refactor vfolder resolver by applying batch result parser
fregataa c4ddfc2
docs: Rename the news fragment with the PR number
jopemachine e108ee7
Merge branch 'main' into fix/broken-vfolder-gql
fregataa 1699e7b
Merge remote-tracking branch 'origin/fix/broken-vfolder-gql' into fix…
fregataa d46cc6e
chore: Fix news fragment
jopemachine 28d3b51
Merge branch 'main' into fix/broken-vfolder-gql
fregataa 77c9f71
Merge branch 'main' into fix/broken-vfolder-gql
fregataa b138ec0
Merge remote-tracking branch 'origin/fix/broken-vfolder-gql' into fix…
fregataa 0cb24a8
chore: `folder_id` -> `vfolder_id`
jopemachine 66d1e7e
chore: Rename news fragment
jopemachine 82e5273
Update 3047.fix.md
jopemachine File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Fix regression of outdated `vfolder` GQL resolver. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,7 @@ | |
List, | ||
NamedTuple, | ||
Optional, | ||
Self, | ||
Sequence, | ||
TypeAlias, | ||
cast, | ||
|
@@ -35,7 +36,7 @@ | |
from sqlalchemy.engine.row import Row | ||
from sqlalchemy.ext.asyncio import AsyncConnection as SAConnection | ||
from sqlalchemy.ext.asyncio import AsyncSession as SASession | ||
from sqlalchemy.orm import load_only, relationship, selectinload | ||
from sqlalchemy.orm import joinedload, load_only, relationship, selectinload | ||
|
||
from ai.backend.common.bgtask import ProgressReporter | ||
from ai.backend.common.types import ( | ||
|
@@ -75,6 +76,7 @@ | |
QuotaScopeIDType, | ||
StrEnumType, | ||
batch_multiresult, | ||
batch_result_in_scalar_stream, | ||
metadata, | ||
) | ||
from .group import GroupRow | ||
|
@@ -1391,40 +1393,67 @@ class Meta: | |
status = graphene.String() | ||
|
||
@classmethod | ||
def from_row(cls, ctx: GraphQueryContext, row: Row | VFolderRow) -> Optional[VirtualFolder]: | ||
if row is None: | ||
return None | ||
|
||
def _get_field(name: str) -> Any: | ||
try: | ||
return row[name] | ||
except sa.exc.NoSuchColumnError: | ||
def from_row(cls, ctx: GraphQueryContext, row: Row | VFolderRow | None) -> Optional[Self]: | ||
match row: | ||
case None: | ||
return None | ||
|
||
return cls( | ||
id=row["id"], | ||
host=row["host"], | ||
quota_scope_id=row["quota_scope_id"], | ||
name=row["name"], | ||
user=row["user"], | ||
user_email=_get_field("users_email"), | ||
group=row["group"], | ||
group_name=_get_field("groups_name"), | ||
creator=row["creator"], | ||
domain_name=row["domain_name"], | ||
unmanaged_path=row["unmanaged_path"], | ||
usage_mode=row["usage_mode"], | ||
permission=row["permission"], | ||
ownership_type=row["ownership_type"], | ||
max_files=row["max_files"], | ||
max_size=row["max_size"], # in MiB | ||
created_at=row["created_at"], | ||
last_used=row["last_used"], | ||
# num_attached=row['num_attached'], | ||
cloneable=row["cloneable"], | ||
status=row["status"], | ||
cur_size=row["cur_size"], | ||
) | ||
case VFolderRow(): | ||
return cls( | ||
id=row.id, | ||
host=row.host, | ||
quota_scope_id=row.quota_scope_id, | ||
name=row.name, | ||
user=row.user, | ||
user_email=row.user_row.email if row.user_row is not None else None, | ||
group=row.group, | ||
group_name=row.group_row.name if row.group_row is not None else None, | ||
creator=row.creator, | ||
domain_name=row.domain_name, | ||
unmanaged_path=row.unmanaged_path, | ||
usage_mode=row.usage_mode, | ||
permission=row.permission, | ||
ownership_type=row.ownership_type, | ||
max_files=row.max_files, | ||
max_size=row.max_size, # in MiB | ||
created_at=row.created_at, | ||
last_used=row.last_used, | ||
cloneable=row.cloneable, | ||
status=row.status, | ||
cur_size=row.cur_size, | ||
) | ||
case Row(): | ||
|
||
def _get_field(name: str) -> Any: | ||
try: | ||
return row[name] | ||
except (KeyError, sa.exc.NoSuchColumnError): | ||
return None | ||
|
||
return cls( | ||
id=row["id"], | ||
host=row["host"], | ||
quota_scope_id=row["quota_scope_id"], | ||
name=row["name"], | ||
user=row["user"], | ||
user_email=_get_field("users_email"), | ||
group=row["group"], | ||
group_name=_get_field("groups_name"), | ||
creator=row["creator"], | ||
domain_name=row["domain_name"], | ||
unmanaged_path=row["unmanaged_path"], | ||
usage_mode=row["usage_mode"], | ||
permission=row["permission"], | ||
ownership_type=row["ownership_type"], | ||
max_files=row["max_files"], | ||
max_size=row["max_size"], # in MiB | ||
created_at=row["created_at"], | ||
last_used=row["last_used"], | ||
# num_attached=row['num_attached'], | ||
cloneable=row["cloneable"], | ||
status=row["status"], | ||
cur_size=row["cur_size"], | ||
) | ||
raise ValueError(f"Type not allowed to parse (t:{type(row)})") | ||
|
||
@classmethod | ||
def from_orm_row(cls, row: VFolderRow) -> VirtualFolder: | ||
|
@@ -1593,20 +1622,19 @@ async def load_slice( | |
async def batch_load_by_id( | ||
cls, | ||
graph_ctx: GraphQueryContext, | ||
ids: list[str], | ||
ids: list[uuid.UUID], | ||
*, | ||
domain_name: str | None = None, | ||
group_id: uuid.UUID | None = None, | ||
user_id: uuid.UUID | None = None, | ||
filter: str | None = None, | ||
) -> Sequence[Sequence[VirtualFolder]]: | ||
domain_name: Optional[str] = None, | ||
group_id: Optional[uuid.UUID] = None, | ||
user_id: Optional[uuid.UUID] = None, | ||
filter: Optional[str] = None, | ||
) -> Sequence[Optional[VirtualFolder]]: | ||
from .user import UserRow | ||
|
||
j = sa.join(VFolderRow, UserRow, VFolderRow.user == UserRow.uuid) | ||
query = ( | ||
sa.select(VFolderRow) | ||
.select_from(j) | ||
.where(VFolderRow.id.in_(ids)) | ||
.options(joinedload(VFolderRow.user_row), joinedload(VFolderRow.group_row)) | ||
.order_by(sa.desc(VFolderRow.created_at)) | ||
) | ||
if user_id is not None: | ||
|
@@ -1619,13 +1647,13 @@ async def batch_load_by_id( | |
qfparser = QueryFilterParser(cls._queryfilter_fieldspec) | ||
query = qfparser.append_filter(query, filter) | ||
async with graph_ctx.db.begin_readonly_session() as db_sess: | ||
return await batch_multiresult( | ||
return await batch_result_in_scalar_stream( | ||
graph_ctx, | ||
db_sess, | ||
query, | ||
cls, | ||
ids, | ||
lambda row: row["user"], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since |
||
lambda row: row.id, | ||
) | ||
|
||
@classmethod | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I want to use
get_loader_by_func
andVirtualFolder.batch_load_by_id
here, but then I'm getting a type error since the return type ofVirtualFolder.batch_load_by_id
differs from whatget_loader_by_func
expects.