Skip to content

Commit

Permalink
fix: Omit null parameter when call usage per period API (#2777) (#2779)
Browse files Browse the repository at this point in the history
Co-authored-by: Sanghun Lee <sanghun@lablup.com>
Co-authored-by: Kyujin Cho <kyujin.cho@lablup.com>
  • Loading branch information
3 people authored Sep 4, 2024
1 parent 17a2e11 commit c78a7f8
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
1 change: 1 addition & 0 deletions changes/2777.fix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Omit null parameter when call `usage-per-period` API.
14 changes: 8 additions & 6 deletions src/ai/backend/client/func/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ async def usage_per_month(cls, month: str, group_ids: Sequence[str]):

@api_function
@classmethod
async def usage_per_period(cls, group_id: str, start_date: str, end_date: str):
async def usage_per_period(cls, group_id: str | None, start_date: str, end_date: str):
"""
Get usage statistics for a group specified by `group_id` for time between
`start_date` and `end_date`.
Expand All @@ -70,14 +70,16 @@ async def usage_per_period(cls, group_id: str, start_date: str, end_date: str):
:param end_date: end date in string format (yyyymmdd).
:param group_id: Groups ID to list usage statistics.
"""
params = {
"start_date": start_date,
"end_date": end_date,
}
if group_id is not None:
params["group_id"] = group_id
rqst = Request(
"GET",
"/resource/usage/period",
params={
"group_id": group_id,
"start_date": start_date,
"end_date": end_date,
},
params=params,
)
async with rqst.fetch() as resp:
return await resp.json()
Expand Down
2 changes: 1 addition & 1 deletion src/ai/backend/manager/api/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@ async def usage_per_month(request: web.Request, params: Any) -> web.Response:
@superadmin_required
@check_api_params(
t.Dict({
t.Key("group_id"): t.String | t.Null,
tx.AliasedKey(["project_id", "group_id"], default=None): t.Null | t.String,
t.Key("start_date"): t.Regexp(r"^\d{8}$", re.ASCII),
t.Key("end_date"): t.Regexp(r"^\d{8}$", re.ASCII),
}),
Expand Down

0 comments on commit c78a7f8

Please sign in to comment.