Skip to content

Commit a4dd055

Browse files
committed
Be explicit about which models we are returning
1 parent 5a222e3 commit a4dd055

File tree

4 files changed

+18
-13
lines changed

4 files changed

+18
-13
lines changed

rctab/routers/accounting/allocations.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ async def post_subscription_allocation(
108108
@router.get("/allocations", response_model=List[AllocationListItem])
109109
async def get_subscription_allocations(
110110
subscription: SubscriptionItem, _: UserRBAC = Depends(token_admin_verified)
111-
) -> Any:
111+
) -> List[AllocationListItem]:
112112
"""Return a list of allocations for a subscription."""
113-
return await get_allocations(subscription.sub_id)
113+
rows = await get_allocations(subscription.sub_id)
114+
return [AllocationListItem(**dict(x)) for x in rows]

rctab/routers/accounting/approvals.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import datetime
44
from datetime import timedelta
5-
from typing import Any, List, Optional
5+
from typing import Any, List
66

77
from fastapi import Depends, HTTPException
88
from sqlalchemy import insert
@@ -143,9 +143,10 @@ async def check_approval(approval: Approval) -> None:
143143
@router.get("/approvals", response_model=List[ApprovalListItem])
144144
async def get_subscription_approvals(
145145
subscription: SubscriptionItem, _: UserRBAC = Depends(token_admin_verified)
146-
) -> Optional[List[ApprovalListItem]]:
146+
) -> List[ApprovalListItem]:
147147
"""Returns a list approvals for a subscription."""
148-
return await get_approvals(subscription.sub_id)
148+
rows = await get_approvals(subscription.sub_id)
149+
return [ApprovalListItem(**dict(x)) for x in rows]
149150

150151

151152
@router.post("/approve", status_code=200)

rctab/routers/accounting/cost_recovery.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -214,21 +214,22 @@ async def calc_cost_recovery_app(
214214
@router.post("/cli-cost-recovery", response_model=List[CostRecovery])
215215
async def post_calc_cost_recovery_cli(
216216
recovery_month: CostRecoveryMonth, user: UserRBAC = Depends(token_admin_verified)
217-
) -> Any:
217+
) -> List[CostRecovery]:
218218
"""Route for the CLI to trigger cost recovery calculation."""
219-
resp = await calc_cost_recovery(
219+
rows = await calc_cost_recovery(
220220
recovery_month, commit_transaction=True, admin=user.oid
221221
)
222222

223-
return resp
223+
return [CostRecovery(**dict(x)) for x in rows]
224224

225225

226226
@router.get("/cli-cost-recovery", response_model=List[CostRecovery])
227227
async def get_calc_cost_recovery_cli(
228228
recovery_month: CostRecoveryMonth, user: UserRBAC = Depends(token_admin_verified)
229-
) -> Any:
229+
) -> List[CostRecovery]:
230230
"""Route for the CLI to do a dry-run of the cost recovery calculation."""
231-
result = await calc_cost_recovery(
231+
rows = await calc_cost_recovery(
232232
recovery_month, commit_transaction=False, admin=user.oid
233233
)
234-
return result
234+
235+
return [CostRecovery(**dict(x)) for x in rows]

rctab/routers/accounting/usage.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,9 @@ async def post_cm_usage(
280280

281281

282282
@router.get("/all-cm-usage", response_model=List[CMUsage])
283-
async def get_cm_usage(_: UserRBAC = Depends(token_admin_verified)) -> Any:
283+
async def get_cm_usage(_: UserRBAC = Depends(token_admin_verified)) -> List[CMUsage]:
284284
"""Get all cost-management data."""
285285
cm_query = select([accounting_models.costmanagement])
286-
return await database.fetch_all(cm_query)
286+
rows = [dict(x) for x in await database.fetch_all(cm_query)]
287+
result = [CMUsage(**x) for x in rows]
288+
return result

0 commit comments

Comments
 (0)