Skip to content

Commit fa263f6

Browse files
remove deprecated
1 parent cd27d98 commit fa263f6

File tree

3 files changed

+28
-22
lines changed

3 files changed

+28
-22
lines changed

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

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ async def update_service_run_last_heartbeat(
161161
row = result.first()
162162
if row is None:
163163
return None
164-
return ServiceRunDB.from_orm(row)
164+
return ServiceRunDB.model_validate(row)
165165

166166
async def update_service_run_stopped_at(
167167
self, data: ServiceRunStoppedAtUpdate
@@ -191,7 +191,7 @@ async def update_service_run_stopped_at(
191191
row = result.first()
192192
if row is None:
193193
return None
194-
return ServiceRunDB.from_orm(row)
194+
return ServiceRunDB.model_validate(row)
195195

196196
async def get_service_run_by_id(
197197
self, service_run_id: ServiceRunId
@@ -204,7 +204,7 @@ async def get_service_run_by_id(
204204
row = result.first()
205205
if row is None:
206206
return None
207-
return ServiceRunDB.from_orm(row)
207+
return ServiceRunDB.model_validate(row)
208208

209209
async def list_service_runs_by_product_and_user_and_wallet(
210210
self,
@@ -309,7 +309,9 @@ async def list_service_runs_by_product_and_user_and_wallet(
309309

310310
result = await conn.execute(query)
311311

312-
return [ServiceRunWithCreditsDB.from_orm(row) for row in result.fetchall()]
312+
return [
313+
ServiceRunWithCreditsDB.model_validate(row) for row in result.fetchall()
314+
]
313315

314316
async def get_osparc_credits_aggregated_by_service(
315317
self,
@@ -405,7 +407,7 @@ async def get_osparc_credits_aggregated_by_service(
405407
return (
406408
cast(int, count_result.scalar()),
407409
[
408-
OsparcCreditsAggregatedByServiceKeyDB.from_orm(row)
410+
OsparcCreditsAggregatedByServiceKeyDB.model_validate(row)
409411
for row in list_result.fetchall()
410412
],
411413
)
@@ -571,7 +573,7 @@ async def list_service_runs_with_running_status_across_all_products(
571573
)
572574
result = await conn.execute(query)
573575

574-
return [ServiceRunForCheckDB.from_orm(row) for row in result.fetchall()]
576+
return [ServiceRunForCheckDB.model_validate(row) for row in result.fetchall()]
575577

576578
async def total_service_runs_with_running_status_across_all_products(
577579
self,
@@ -620,7 +622,7 @@ async def update_service_missed_heartbeat_counter(
620622
row = result.first()
621623
if row is None:
622624
return None
623-
return ServiceRunDB.from_orm(row)
625+
return ServiceRunDB.model_validate(row)
624626

625627
#################################
626628
# Credit transactions
@@ -847,7 +849,7 @@ def _version(column_or_value):
847849
result = await conn.execute(query)
848850

849851
return [
850-
PricingPlansWithServiceDefaultPlanDB.from_orm(row)
852+
PricingPlansWithServiceDefaultPlanDB.model_validate(row)
851853
for row in result.fetchall()
852854
]
853855

@@ -873,7 +875,7 @@ async def get_pricing_plan(
873875
raise CustomResourceUsageTrackerError(
874876
msg=f"Pricing plan does not exists: {pricing_plan_id}"
875877
)
876-
return PricingPlansDB.from_orm(row)
878+
return PricingPlansDB.model_validate(row)
877879

878880
async def list_pricing_plans_by_product(
879881
self, product_name: ProductName
@@ -890,7 +892,7 @@ async def list_pricing_plans_by_product(
890892
).where(resource_tracker_pricing_plans.c.product_name == product_name)
891893
result = await conn.execute(select_stmt)
892894

893-
return [PricingPlansDB.from_orm(row) for row in result.fetchall()]
895+
return [PricingPlansDB.model_validate(row) for row in result.fetchall()]
894896

895897
async def create_pricing_plan(self, data: PricingPlanCreate) -> PricingPlansDB:
896898
async with self.db_engine.begin() as conn:
@@ -924,7 +926,7 @@ async def create_pricing_plan(self, data: PricingPlanCreate) -> PricingPlansDB:
924926
raise CustomResourceUsageTrackerError(
925927
msg=f"Pricing plan was not created: {data}"
926928
)
927-
return PricingPlansDB.from_orm(row)
929+
return PricingPlansDB.model_validate(row)
928930

929931
async def update_pricing_plan(
930932
self, product_name: ProductName, data: PricingPlanUpdate
@@ -961,7 +963,7 @@ async def update_pricing_plan(
961963
row = result.first()
962964
if row is None:
963965
return None
964-
return PricingPlansDB.from_orm(row)
966+
return PricingPlansDB.model_validate(row)
965967

966968
#################################
967969
# Pricing plan to service
@@ -1000,7 +1002,9 @@ async def list_connected_services_to_pricing_plan_by_pricing_plan(
10001002
)
10011003
result = await conn.execute(query)
10021004

1003-
return [PricingPlanToServiceDB.from_orm(row) for row in result.fetchall()]
1005+
return [
1006+
PricingPlanToServiceDB.model_validate(row) for row in result.fetchall()
1007+
]
10041008

10051009
async def upsert_service_to_pricing_plan(
10061010
self,
@@ -1087,7 +1091,7 @@ async def upsert_service_to_pricing_plan(
10871091
raise CustomResourceUsageTrackerError(
10881092
msg="Pricing plan to service record was not created"
10891093
)
1090-
return PricingPlanToServiceDB.from_orm(row)
1094+
return PricingPlanToServiceDB.model_validate(row)
10911095

10921096
#################################
10931097
# Pricing units
@@ -1145,7 +1149,7 @@ async def list_pricing_units_by_pricing_plan(
11451149
)
11461150
result = await conn.execute(query)
11471151

1148-
return [PricingUnitsDB.from_orm(row) for row in result.fetchall()]
1152+
return [PricingUnitsDB.model_validate(row) for row in result.fetchall()]
11491153

11501154
async def get_valid_pricing_unit(
11511155
self,
@@ -1197,7 +1201,7 @@ async def get_valid_pricing_unit(
11971201
raise CustomResourceUsageTrackerError(
11981202
msg=f"Pricing plan {pricing_plan_id} and pricing unit {pricing_unit_id} for product {product_name} not found"
11991203
)
1200-
return PricingUnitsDB.from_orm(row)
1204+
return PricingUnitsDB.model_validate(row)
12011205

12021206
async def create_pricing_unit_with_cost(
12031207
self, data: PricingUnitWithCostCreate, pricing_plan_key: str
@@ -1348,4 +1352,4 @@ async def get_pricing_unit_cost_by_id(
13481352
raise CustomResourceUsageTrackerError(
13491353
msg=f"Pricing unit cost id {pricing_unit_cost_id} not found in the resource_tracker_pricing_unit_costs table",
13501354
)
1351-
return PricingUnitCostsDB.from_orm(row)
1355+
return PricingUnitCostsDB.model_validate(row)

services/resource-usage-tracker/tests/unit/with_dbs/conftest.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ async def assert_service_runs_db_row(
177177
)
178178
row = result.first()
179179
assert row
180-
service_run_db = ServiceRunDB.from_orm(row)
180+
service_run_db = ServiceRunDB.model_validate(row)
181181
if status:
182182
assert service_run_db.service_run_status == status
183183
return service_run_db
@@ -202,7 +202,7 @@ async def assert_credit_transactions_db_row(
202202
)
203203
row = result.first()
204204
assert row
205-
credit_transaction_db = CreditTransactionDB.from_orm(row)
205+
credit_transaction_db = CreditTransactionDB.model_validate(row)
206206
if modified_at:
207207
assert credit_transaction_db.modified > modified_at
208208
return credit_transaction_db

services/resource-usage-tracker/tests/unit/with_dbs/test_background_task.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ async def test_process_event_functions(
152152
# Check max acceptable missed heartbeats reached before considering them as unhealthy
153153
with postgres_db.connect() as con:
154154
result = con.execute(sa.select(resource_tracker_service_runs))
155-
service_run_db = [ServiceRunDB.from_orm(row) for row in result]
155+
service_run_db = [ServiceRunDB.model_validate(row) for row in result]
156156
for service_run in service_run_db:
157157
if service_run.service_run_id in (
158158
_SERVICE_RUN_ID_OSPARC_10_MIN_OLD,
@@ -172,7 +172,7 @@ async def test_process_event_functions(
172172

173173
with postgres_db.connect() as con:
174174
result = con.execute(sa.select(resource_tracker_service_runs))
175-
service_run_db = [ServiceRunDB.from_orm(row) for row in result]
175+
service_run_db = [ServiceRunDB.model_validate(row) for row in result]
176176
for service_run in service_run_db:
177177
if service_run.service_run_id in (
178178
_SERVICE_RUN_ID_OSPARC_10_MIN_OLD,
@@ -186,7 +186,9 @@ async def test_process_event_functions(
186186

187187
with postgres_db.connect() as con:
188188
result = con.execute(sa.select(resource_tracker_credit_transactions))
189-
credit_transaction_db = [CreditTransactionDB.from_orm(row) for row in result]
189+
credit_transaction_db = [
190+
CreditTransactionDB.model_validate(row) for row in result
191+
]
190192
for transaction in credit_transaction_db:
191193
if transaction.service_run_id in (
192194
_SERVICE_RUN_ID_OSPARC_10_MIN_OLD,

0 commit comments

Comments
 (0)