Skip to content

Commit 824e147

Browse files
continue upgrading
1 parent 7eea28e commit 824e147

File tree

6 files changed

+38
-48
lines changed

6 files changed

+38
-48
lines changed

services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/core/settings.py

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from functools import cached_property
33

44
from models_library.basic_types import BootModeEnum
5-
from pydantic import Field, PositiveInt, validator
5+
from pydantic import AliasChoices, field_validator, Field, PositiveInt
66
from settings_library.base import BaseCustomSettings
77
from settings_library.basic_types import BuildTargetEnum, LogLevel, VersionTag
88
from settings_library.postgres import PostgresSettings
@@ -44,26 +44,32 @@ class _BaseApplicationSettings(BaseCustomSettings, MixinLoggingSettings):
4444
RESOURCE_USAGE_TRACKER_DEBUG: bool = Field(
4545
default=False,
4646
description="Debug mode",
47-
env=["RESOURCE_USAGE_TRACKER_DEBUG", "DEBUG"],
47+
validation_alias=AliasChoices(
48+
"RESOURCE_USAGE_TRACKER_DEBUG",
49+
"DEBUG",
50+
),
4851
)
4952
RESOURCE_USAGE_TRACKER_LOGLEVEL: LogLevel = Field(
5053
default=LogLevel.INFO,
51-
env=["RESOURCE_USAGE_TRACKER_LOGLEVEL", "LOG_LEVEL", "LOGLEVEL"],
54+
validation_alias=AliasChoices(
55+
"RESOURCE_USAGE_TRACKER_LOGLEVEL",
56+
"LOG_LEVEL",
57+
"LOGLEVEL"),
5258
)
5359
RESOURCE_USAGE_TRACKER_LOG_FORMAT_LOCAL_DEV_ENABLED: bool = Field(
5460
default=False,
55-
env=[
61+
validation_alias=AliasChoices(
5662
"RESOURCE_USAGE_TRACKER_LOG_FORMAT_LOCAL_DEV_ENABLED",
5763
"LOG_FORMAT_LOCAL_DEV_ENABLED",
58-
],
64+
),
5965
description="Enables local development log format. WARNING: make sure it is disabled if you want to have structured logs!",
6066
)
6167

6268
@cached_property
6369
def LOG_LEVEL(self) -> LogLevel: # noqa: N802
6470
return self.RESOURCE_USAGE_TRACKER_LOGLEVEL
6571

66-
@validator("RESOURCE_USAGE_TRACKER_LOGLEVEL")
72+
@field_validator("RESOURCE_USAGE_TRACKER_LOGLEVEL")
6773
@classmethod
6874
def valid_log_level(cls, value: str) -> str:
6975
return cls.validate_log_level(value)
@@ -77,16 +83,18 @@ class MinimalApplicationSettings(_BaseApplicationSettings):
7783
"""
7884

7985
RESOURCE_USAGE_TRACKER_PROMETHEUS: PrometheusSettings | None = Field(
80-
auto_default_from_env=True
86+
json_schema_extra={"auto_default_from_env":True}
8187
)
8288

8389
RESOURCE_USAGE_TRACKER_POSTGRES: PostgresSettings | None = Field(
84-
auto_default_from_env=True
90+
json_schema_extra={"auto_default_from_env":True},
8591
)
8692

87-
RESOURCE_USAGE_TRACKER_REDIS: RedisSettings = Field(auto_default_from_env=True)
93+
RESOURCE_USAGE_TRACKER_REDIS: RedisSettings = Field(
94+
json_schema_extra={"auto_default_from_env":True},
95+
)
8896
RESOURCE_USAGE_TRACKER_RABBITMQ: RabbitSettings | None = Field(
89-
auto_default_from_env=True
97+
json_schema_extra={"auto_default_from_env":True},
9098
)
9199

92100

@@ -109,4 +117,6 @@ class ApplicationSettings(MinimalApplicationSettings):
109117
description="Heartbeat couter limit when RUT considers service as unhealthy.",
110118
)
111119
RESOURCE_USAGE_TRACKER_PROMETHEUS_INSTRUMENTATION_ENABLED: bool = True
112-
RESOURCE_USAGE_TRACKER_S3: S3Settings | None = Field(auto_default_from_env=True)
120+
RESOURCE_USAGE_TRACKER_S3: S3Settings | None = Field(
121+
json_schema_extra={"auto_default_from_env":True},
122+
)

services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/models/resource_tracker_credit_transactions.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
)
1414
from models_library.users import UserID
1515
from models_library.wallets import WalletID
16-
from pydantic import BaseModel
16+
from pydantic import ConfigDict, BaseModel
1717

1818

1919
class CreditTransactionCreate(BaseModel):
@@ -64,6 +64,4 @@ class CreditTransactionDB(BaseModel):
6464
created: datetime
6565
last_heartbeat_at: datetime
6666
modified: datetime
67-
68-
class Config:
69-
orm_mode = True
67+
model_config = ConfigDict(from_attributes=True)

services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/models/resource_tracker_pricing_plans.py

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

33
from models_library.resource_tracker import PricingPlanClassification, PricingPlanId
44
from models_library.services import ServiceKey, ServiceVersion
5-
from pydantic import BaseModel
5+
from pydantic import ConfigDict, BaseModel
66

77
## DB Models
88

@@ -15,23 +15,17 @@ class PricingPlansDB(BaseModel):
1515
is_active: bool
1616
created: datetime
1717
pricing_plan_key: str
18-
19-
class Config:
20-
orm_mode = True
18+
model_config = ConfigDict(from_attributes=True)
2119

2220

2321
class PricingPlansWithServiceDefaultPlanDB(PricingPlansDB):
2422
service_default_plan: bool
25-
26-
class Config:
27-
orm_mode = True
23+
model_config = ConfigDict(from_attributes=True)
2824

2925

3026
class PricingPlanToServiceDB(BaseModel):
3127
pricing_plan_id: PricingPlanId
3228
service_key: ServiceKey
3329
service_version: ServiceVersion
3430
created: datetime
35-
36-
class Config:
37-
orm_mode = True
31+
model_config = ConfigDict(from_attributes=True)

services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/models/resource_tracker_pricing_unit_costs.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
PricingUnitCostId,
77
PricingUnitId,
88
)
9-
from pydantic import BaseModel
9+
from pydantic import ConfigDict, BaseModel
1010

1111

1212
class PricingUnitCostsDB(BaseModel):
@@ -21,6 +21,4 @@ class PricingUnitCostsDB(BaseModel):
2121
created: datetime
2222
comment: str | None
2323
modified: datetime
24-
25-
class Config:
26-
orm_mode = True
24+
model_config = ConfigDict(from_attributes=True)

services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/models/resource_tracker_pricing_units.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
PricingUnitId,
1010
UnitExtraInfo,
1111
)
12-
from pydantic import BaseModel, validator
12+
from pydantic import field_validator, ConfigDict, BaseModel
1313

1414

1515
class PricingUnitsDB(BaseModel):
@@ -23,11 +23,9 @@ class PricingUnitsDB(BaseModel):
2323
modified: datetime
2424
current_cost_per_unit: Decimal
2525
current_cost_per_unit_id: PricingUnitCostId
26+
model_config = ConfigDict(from_attributes=True)
2627

27-
class Config:
28-
orm_mode = True
29-
30-
@validator("specific_info", pre=True)
28+
@field_validator("specific_info", mode="before")
3129
@classmethod
3230
def default_hardware_info_when_empty(cls, v) -> HardwareInfo | Any:
3331
if not v:

services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/models/resource_tracker_service_runs.py

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
from models_library.services import ServiceKey, ServiceVersion
1717
from models_library.users import UserID
1818
from models_library.wallets import WalletID
19-
from pydantic import BaseModel, NonNegativeInt
19+
from pydantic import ConfigDict, BaseModel, NonNegativeInt
2020

2121

2222
class ServiceRunCreate(BaseModel):
@@ -93,32 +93,24 @@ class ServiceRunDB(BaseModel):
9393
last_heartbeat_at: datetime
9494
service_run_status_msg: str | None
9595
missed_heartbeat_counter: NonNegativeInt
96-
97-
class Config:
98-
orm_mode = True
96+
model_config = ConfigDict(from_attributes=True)
9997

10098

10199
class ServiceRunWithCreditsDB(ServiceRunDB):
102-
osparc_credits: Decimal | None
100+
osparc_credits: Decimal | None = None
103101
transaction_status: CreditTransactionStatus | None
104-
105-
class Config:
106-
orm_mode = True
102+
model_config = ConfigDict(from_attributes=True)
107103

108104

109105
class OsparcCreditsAggregatedByServiceKeyDB(BaseModel):
110106
osparc_credits: Decimal
111107
service_key: ServiceKey
112-
113-
class Config:
114-
orm_mode = True
108+
model_config = ConfigDict(from_attributes=True)
115109

116110

117111
class ServiceRunForCheckDB(BaseModel):
118112
service_run_id: ServiceRunId
119113
last_heartbeat_at: datetime
120114
missed_heartbeat_counter: NonNegativeInt
121115
modified: datetime
122-
123-
class Config:
124-
orm_mode = True
116+
model_config = ConfigDict(from_attributes=True)

0 commit comments

Comments
 (0)