Skip to content

Commit 84eb893

Browse files
review @pcrespov
1 parent 1ee8886 commit 84eb893

File tree

5 files changed

+25
-15
lines changed

5 files changed

+25
-15
lines changed

packages/postgres-database/src/simcore_postgres_database/migration/versions/aa6da21a0055_rename_usages_to_checkouts.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""rename usages to checkouts
22
33
Revision ID: aa6da21a0055
4-
Revises: 77ac824a77ff
4+
Revises: 52a0e8148dd5
55
Create Date: 2024-12-17 13:47:09.304574+00:00
66
77
"""
@@ -11,7 +11,7 @@
1111

1212
# revision identifiers, used by Alembic.
1313
revision = "aa6da21a0055"
14-
down_revision = "77ac824a77ff"
14+
down_revision = "52a0e8148dd5"
1515
branch_labels = None
1616
depends_on = None
1717

services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/services/modules/db/licensed_items_checkouts_db.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,8 @@ async def list_(
114114

115115
async with pass_or_acquire_connection(engine, connection) as conn:
116116
total_count = await conn.scalar(count_query)
117+
if total_count is None:
118+
total_count = 0
117119

118120
result = await conn.stream(list_query)
119121
items: list[LicensedItemCheckoutDB] = [
@@ -208,8 +210,7 @@ async def get_currently_used_seats_for_item_and_wallet(
208210
)
209211

210212
async with pass_or_acquire_connection(engine, connection) as conn:
211-
result = await conn.execute(sum_stmt)
212-
row = result.first()
213-
if row is None or row[0] is None:
213+
total_sum = await conn.scalar(sum_stmt)
214+
if total_sum is None:
214215
return 0
215-
return int(row[0])
216+
return cast(int, total_sum)

services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/services/modules/db/licensed_items_purchases_db.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,8 @@ async def list_(
116116

117117
async with pass_or_acquire_connection(engine, connection) as conn:
118118
total_count = await conn.scalar(count_query)
119+
if total_count is None:
120+
total_count = 0
119121

120122
result = await conn.stream(list_query)
121123
items: list[LicensedItemsPurchasesDB] = [
@@ -181,8 +183,7 @@ async def get_active_purchased_seats_for_item_and_wallet(
181183
)
182184

183185
async with pass_or_acquire_connection(engine, connection) as conn:
184-
result = await conn.execute(sum_stmt)
185-
row = result.first()
186-
if row is None or row[0] is None:
186+
total_sum = await conn.scalar(sum_stmt)
187+
if total_sum is None:
187188
return 0
188-
return int(row[0])
189+
return cast(int, total_sum)

services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/services/modules/db/service_runs_db.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,9 @@ async def get_osparc_credits_aggregated_by_service(
376376

377377
subquery = base_query.subquery()
378378
count_query = sa.select(sa.func.count()).select_from(subquery)
379-
count_result = await conn.execute(count_query)
379+
count_result = await conn.scalar(count_query)
380+
if count_result is None:
381+
count_result = 0
380382

381383
# Default ordering and pagination
382384
list_query = (
@@ -387,7 +389,7 @@ async def get_osparc_credits_aggregated_by_service(
387389
list_result = await conn.execute(list_query)
388390

389391
return (
390-
cast(int, count_result.scalar()),
392+
cast(int, count_result),
391393
[
392394
OsparcCreditsAggregatedByServiceKeyDB.model_validate(row)
393395
for row in list_result.fetchall()

services/web/server/src/simcore_service_webserver/licenses/_licensed_checkouts_api.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,15 @@
2424

2525
async def checkout_licensed_item_for_wallet(
2626
app: web.Application,
27-
licensed_item_id: LicensedItemID,
28-
wallet_id: WalletID,
27+
*,
28+
# access context
2929
product_name: ProductName,
30+
wallet_id: WalletID,
31+
user_id: UserID,
32+
# checkout args
33+
licensed_item_id: LicensedItemID,
3034
num_of_seats: int,
3135
service_run_id: ServiceRunId,
32-
user_id: UserID,
3336
) -> webserver_licensed_items_checkouts.LicensedItemCheckoutGet:
3437
# Check whether user has access to the wallet
3538
await get_wallet_by_user(
@@ -69,8 +72,11 @@ async def checkout_licensed_item_for_wallet(
6972

7073
async def release_licensed_item_for_wallet(
7174
app: web.Application,
75+
*,
76+
# access context
7277
product_name: ProductName,
7378
user_id: UserID,
79+
# release args
7480
licensed_item_checkout_id: LicensedItemCheckoutID,
7581
) -> webserver_licensed_items_checkouts.LicensedItemCheckoutGet:
7682
rpc_client = get_rabbitmq_rpc_client(app)

0 commit comments

Comments
 (0)