Skip to content

Commit

Permalink
fix:let vfolder GET requests contain data in params rather than body (#…
Browse files Browse the repository at this point in the history
…2706) (#2714)

Co-authored-by: pilmo kim <68311908+why-arong@users.noreply.github.com>
Co-authored-by: Kyujin Cho <kyujin.cho@lablup.com>
  • Loading branch information
3 people authored Aug 14, 2024
1 parent 3b506ee commit 67e8dad
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 17 deletions.
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

0 comments on commit 67e8dad

Please sign in to comment.