-
-
Notifications
You must be signed in to change notification settings - Fork 10.1k
fix(vector-stores): paginate managed resource list by unified_resource_id cursor #34596
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
base: litellm_internal_staging
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -542,35 +542,39 @@ async def list_user_resources( | |
| Returns: | ||
| Dictionary with list of resources and pagination info | ||
| """ | ||
| from fastapi import HTTPException | ||
|
|
||
| owner_filter = build_owner_filter(user_api_key_dict) | ||
| if owner_filter is None: | ||
| return build_list_page([]) | ||
|
|
||
| where_clause: Dict[str, Any] = {**owner_filter} | ||
| where_clause: Dict[str, Any] = {**owner_filter, **(additional_filters or {})} | ||
|
|
||
| table = getattr(self.prisma_client.db, self.table_name) | ||
|
|
||
| if after: | ||
| where_clause["id"] = {"gt": after} | ||
| cursor_row = await table.find_first(where={**where_clause, "unified_resource_id": after}) | ||
| if cursor_row is None: | ||
| raise HTTPException( | ||
| status_code=400, | ||
| detail=f"Invalid 'after' cursor: no {self.resource_type} found with id '{after}'.", | ||
| ) | ||
|
|
||
| # Add additional filters | ||
| if additional_filters: | ||
| where_clause.update(additional_filters) | ||
| page_size = limit or 20 | ||
| cursor_args: Dict[str, Any] = {"cursor": {"unified_resource_id": after}, "skip": 1} if after else {} | ||
|
|
||
| # Fetch resources | ||
| fetch_limit = limit or 20 | ||
| table = getattr(self.prisma_client.db, self.table_name) | ||
| resources = await table.find_many( | ||
| where=where_clause, | ||
| take=fetch_limit, | ||
| order={"created_at": "desc"}, | ||
| take=page_size + 1, | ||
| order=[{"created_at": "desc"}, {"unified_resource_id": "desc"}], | ||
| **cursor_args, | ||
| ) | ||
|
|
||
| has_more = len(resources) > page_size | ||
|
|
||
| resource_objects: List[Any] = [] | ||
|
Contributor
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.
|
||
| for resource in resources: | ||
| for resource in resources[:page_size]: | ||
| try: | ||
| # Stop once we have enough | ||
| if len(resource_objects) >= (limit or 20): | ||
| break | ||
|
|
||
| # Parse resource object | ||
| resource_data = resource.resource_object | ||
| if isinstance(resource_data, str): | ||
|
|
@@ -590,4 +594,4 @@ async def list_user_resources( | |
| ) | ||
| continue | ||
|
|
||
| return build_list_page(resource_objects, has_more=len(resource_objects) == (limit or 20)) | ||
| return build_list_page(resource_objects, has_more=has_more) | ||
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.
list_user_resourcesnow imports FastAPI on every call, so SDK-only installations without the proxy extra raiseModuleNotFoundErrorbefore executing the listing. Keep proxy exception mapping outside this SDK-layer module or use an exception available in the core dependency setRule Used: What: Do not allow fastapi imports on files outsid... (source)
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!