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:let vfolder GET requests contain data in params rather than body (#2706) #2714

Merged
merged 1 commit into from
Aug 14, 2024
Merged
Show file tree
Hide file tree
Changes from all 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/2706.fix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix `list_files`, `get_fstab_contents`, `get_performance_metric` and `shared_vfolder_info` Python SDK function not working with `ValidationError` exception printed
24 changes: 10 additions & 14 deletions src/ai/backend/client/func/vfolder.py
Original file line number Diff line number Diff line change
Expand Up @@ -547,10 +547,7 @@ async def delete_files(self, files: Sequence[Union[str, Path]], recursive: bool

@api_function
async def list_files(self, path: Union[str, Path] = "."):
rqst = Request("GET", "/folders/{}/files".format(self.name))
rqst.set_json({
"path": path,
})
rqst = Request("GET", "/folders/{}/files".format(self.name), params={"path": str(path)})
async with rqst.fetch() as resp:
return await resp.json()

Expand Down Expand Up @@ -590,20 +587,20 @@ async def delete_invitation(cls, inv_id: str):
@api_function
@classmethod
async def get_fstab_contents(cls, agent_id=None):
rqst = Request("GET", "/folders/_/fstab")
rqst.set_json({
"agent_id": agent_id,
})
rqst = Request(
"GET",
"/folders/_/fstab",
params={
"agent_id": agent_id,
},
)
async with rqst.fetch() as resp:
return await resp.json()

@api_function
@classmethod
async def get_performance_metric(cls, folder_host: str):
rqst = Request("GET", "/folders/_/perf-metric")
rqst.set_json({
"folder_host": folder_host,
})
rqst = Request("GET", "/folders/_/perf-metric", params={"folder_host": folder_host})
async with rqst.fetch() as resp:
return await resp.json()

Expand Down Expand Up @@ -702,8 +699,7 @@ async def list_shared_vfolders(cls):
@api_function
@classmethod
async def shared_vfolder_info(cls, vfolder_id: str):
rqst = Request("GET", "folders/_/shared")
rqst.set_json({"vfolder_id": vfolder_id})
rqst = Request("GET", "folders/_/shared", params={"vfolder_id": vfolder_id})
async with rqst.fetch() as resp:
return await resp.json()

Expand Down
11 changes: 8 additions & 3 deletions tests/client/test_vfolder.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
from typing import Mapping, Union
from unittest import mock

import pytest
from aioresponses import aioresponses

from ai.backend.client.config import API_VERSION
from ai.backend.client.config import API_VERSION, APIConfig
from ai.backend.client.session import Session
from ai.backend.testutils.mock import AsyncMock


def build_url(config, path: str):
def build_url(config: APIConfig, path: str, params: Mapping[str, Union[str, int]] = None):
base_url = config.endpoint.path.rstrip("/")
query_path = path.lstrip("/") if len(path) > 0 else ""
path = "{0}/{1}".format(base_url, query_path)
canonical_url = config.endpoint.with_path(path)
if params:
canonical_url = canonical_url.with_query(params)
return canonical_url


Expand Down Expand Up @@ -138,7 +141,9 @@ def test_vfolder_list_files():
"folder_path": "/mnt/local/1f6bd27fde1248cabfb50306ea83fc0a",
}
m.get(
build_url(session.config, "/folders/{}/files".format(vfolder_name)),
build_url(
session.config, "/folders/{}/files".format(vfolder_name), params={"path": "."}
),
status=200,
payload=payload,
)
Expand Down
Loading