Skip to content

Commit 580cc39

Browse files
continue upgrading
1 parent ca1aad2 commit 580cc39

File tree

5 files changed

+42
-36
lines changed

5 files changed

+42
-36
lines changed

packages/postgres-database/src/simcore_postgres_database/models/products.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,13 @@
66
"""
77

88
import json
9-
from typing import Literal, TypedDict
9+
import sys
10+
from typing import Literal
11+
12+
if sys.version_info >= (3, 12):
13+
from typing import TypedDict
14+
else:
15+
from typing_extensions import TypedDict # See: https://docs.pydantic.dev/2.9/errors/usage_errors/#typed-dict-version
1016

1117
import sqlalchemy as sa
1218
from sqlalchemy.dialects.postgresql import JSONB

services/web/server/src/simcore_service_webserver/application_settings.py

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from typing import Any, Final
44

55
from aiohttp import web
6+
from common_library.pydantic_fields_extension import is_nullable
67
from models_library.basic_types import (
78
BootModeEnum,
89
BuildTargetEnum,
@@ -11,8 +12,8 @@
1112
VersionTag,
1213
)
1314
from models_library.utils.change_case import snake_to_camel
14-
from pydantic import AliasChoices, TypeAdapter, field_validator, model_validator, AnyHttpUrl
15-
from pydantic.fields import Field, ModelField
15+
from pydantic import AliasChoices, TypeAdapter, ValidationInfo, field_validator, model_validator, AnyHttpUrl
16+
from pydantic.fields import Field
1617
from pydantic.types import PositiveInt
1718
from settings_library.base import BaseCustomSettings
1819
from settings_library.email import SMTPSettings
@@ -105,12 +106,12 @@ class ApplicationSettings(BaseCustomSettings, MixinLoggingSettings):
105106
)
106107
WEBSERVER_LOGLEVEL: LogLevel = Field(
107108
default=LogLevel.WARNING.value,
108-
env=["WEBSERVER_LOGLEVEL", "LOG_LEVEL", "LOGLEVEL"],
109+
validation_alias=AliasChoices("WEBSERVER_LOGLEVEL", "LOG_LEVEL", "LOGLEVEL"),
109110
# NOTE: suffix '_LOGLEVEL' is used overall
110111
)
111112
WEBSERVER_LOG_FORMAT_LOCAL_DEV_ENABLED: bool = Field(
112113
default=False,
113-
env=["WEBSERVER_LOG_FORMAT_LOCAL_DEV_ENABLED", "LOG_FORMAT_LOCAL_DEV_ENABLED"],
114+
validation_alias=AliasChoices("WEBSERVER_LOG_FORMAT_LOCAL_DEV_ENABLED", "LOG_FORMAT_LOCAL_DEV_ENABLED"),
114115
description="Enables local development log format. WARNING: make sure it is disabled if you want to have structured logs!",
115116
)
116117
# TODO: find a better name!?
@@ -168,51 +169,50 @@ class ApplicationSettings(BaseCustomSettings, MixinLoggingSettings):
168169
)
169170

170171
WEBSERVER_DYNAMIC_SCHEDULER: DynamicSchedulerSettings | None = Field(
171-
auto_default_from_env=True, description="dynamic-scheduler plugin settings"
172+
description="dynamic-scheduler plugin settings", json_schema_extra={"auto_default_from_env": True}
172173
)
173174

174-
WEBSERVER_REDIS: RedisSettings | None = Field(auto_default_from_env=True)
175+
WEBSERVER_REDIS: RedisSettings | None = Field(json_schema_extra={"auto_default_from_env": True})
175176

176177
WEBSERVER_REST: RestSettings | None = Field(
177-
auto_default_from_env=True, description="rest api plugin"
178+
description="rest api plugin", json_schema_extra={"auto_default_from_env": True}
178179
)
179180

180181
WEBSERVER_RESOURCE_MANAGER: ResourceManagerSettings = Field(
181-
auto_default_from_env=True, description="resource_manager plugin"
182+
description="resource_manager plugin", json_schema_extra={"auto_default_from_env": True}
182183
)
183184
WEBSERVER_RESOURCE_USAGE_TRACKER: ResourceUsageTrackerSettings | None = Field(
184-
auto_default_from_env=True,
185-
description="resource usage tracker service client's plugin",
185+
description="resource usage tracker service client's plugin", json_schema_extra={"auto_default_from_env": True}
186186
)
187187
WEBSERVER_SCICRUNCH: SciCrunchSettings | None = Field(
188-
auto_default_from_env=True, description="scicrunch plugin"
188+
description="scicrunch plugin", json_schema_extra={"auto_default_from_env": True}
189189
)
190190
WEBSERVER_SESSION: SessionSettings = Field(
191-
auto_default_from_env=True, description="session plugin"
191+
description="session plugin", json_schema_extra={"auto_default_from_env": True}
192192
)
193193

194194
WEBSERVER_STATICWEB: StaticWebserverModuleSettings | None = Field(
195-
auto_default_from_env=True, description="static-webserver service plugin"
195+
description="static-webserver service plugin", json_schema_extra={"auto_default_from_env": True}
196196
)
197197
WEBSERVER_STORAGE: StorageSettings | None = Field(
198-
auto_default_from_env=True, description="storage service client's plugin"
198+
description="storage service client's plugin", json_schema_extra={"auto_default_from_env": True}
199199
)
200200
WEBSERVER_STUDIES_DISPATCHER: StudiesDispatcherSettings | None = Field(
201-
auto_default_from_env=True, description="studies dispatcher plugin"
201+
description="studies dispatcher plugin", json_schema_extra={"auto_default_from_env": True}
202202
)
203203

204204
WEBSERVER_TRACING: TracingSettings | None = Field(
205-
auto_default_from_env=True, description="tracing plugin"
205+
description="tracing plugin", json_schema_extra={"auto_default_from_env": True}
206206
)
207207

208208
WEBSERVER_PROJECTS: ProjectsSettings | None = Field(
209-
auto_default_from_env=True, description="projects plugin"
209+
description="projects plugin", json_schema_extra={"auto_default_from_env": True}
210210
)
211211
WEBSERVER_RABBITMQ: RabbitSettings | None = Field(
212-
auto_default_from_env=True, description="rabbitmq plugin"
212+
description="rabbitmq plugin", json_schema_extra={"auto_default_from_env": True}
213213
)
214214
WEBSERVER_USERS: UsersSettings | None = Field(
215-
auto_default_from_env=True, description="users plugin"
215+
description="users plugin", json_schema_extra={"auto_default_from_env": True}
216216
)
217217

218218
# These plugins only require (for the moment) an entry to toggle between enabled/disabled
@@ -268,17 +268,18 @@ def build_vcs_release_url_if_unset(cls, values):
268268
mode="before"
269269
)
270270
@classmethod
271-
def enable_only_if_dev_features_allowed(cls, v, values, field: ModelField):
271+
def enable_only_if_dev_features_allowed(cls, v, info: ValidationInfo):
272272
"""Ensures that plugins 'under development' get programatically
273273
disabled if WEBSERVER_DEV_FEATURES_ENABLED=False
274274
"""
275-
if values["WEBSERVER_DEV_FEATURES_ENABLED"]:
275+
if info.data["WEBSERVER_DEV_FEATURES_ENABLED"]:
276276
return v
277277
if v:
278278
_logger.warning(
279-
"%s still under development and will be disabled.", field.name
279+
"%s still under development and will be disabled.", info.field_name
280280
)
281-
return None if field.allow_none else False
281+
282+
return None if info.field_name and is_nullable(cls.model_fields[info.field_name]) else False
282283

283284
@cached_property
284285
def log_level(self) -> int:

services/web/server/src/simcore_service_webserver/login/settings.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ class LoginSettings(BaseCustomSettings):
3636
)
3737

3838
LOGIN_TWILIO: TwilioSettings | None = Field(
39-
auto_default_from_env=True,
4039
description="Twilio service settings. Used to send SMS for 2FA",
40+
json_schema_extra={"auto_default_from_env=True": True}
4141
)
4242

4343
LOGIN_2FA_CODE_EXPIRATION_SEC: PositiveInt = Field(
@@ -94,7 +94,7 @@ def create_from_composition(
9494
"""
9595
For the LoginSettings, product-specific settings override app-specifics settings
9696
"""
97-
composed_settings = {**app_login_settings.dict(), **product_login_settings}
97+
composed_settings = {**app_login_settings.model_dump(), **product_login_settings}
9898

9999
if "two_factor_enabled" in composed_settings:
100100
# legacy safe

services/web/server/src/simcore_service_webserver/products/_model.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import logging
22
import string
3-
from typing import ( # noqa: UP035 # pydantic does not validate with re.Pattern
4-
Any,
5-
Pattern,
3+
from typing import (
4+
Any
65
)
6+
import re
77

88
from models_library.basic_regex import (
99
PUBLIC_VARIABLE_NAME_RE,
@@ -44,14 +44,13 @@ class Product(BaseModel):
4444
display_name: str = Field(..., description="Long display name")
4545
short_name: str | None = Field(
4646
None,
47-
pattern=TWILIO_ALPHANUMERIC_SENDER_ID_RE,
47+
pattern=re.compile(TWILIO_ALPHANUMERIC_SENDER_ID_RE),
4848
min_length=2,
4949
max_length=11,
5050
description="Short display name for SMS",
5151
)
5252

53-
host_regex: Pattern = Field(..., description="Host regex")
54-
# NOTE: typing.Pattern is supported but not re.Pattern (SEE https://github.com/pydantic/pydantic/pull/4366)
53+
host_regex: re.Pattern = Field(..., description="Host regex")
5554

5655
support_email: LowerCaseEmailStr = Field(
5756
...,
@@ -110,15 +109,15 @@ class Product(BaseModel):
110109

111110
@field_validator("*", mode="before")
112111
@classmethod
113-
def parse_empty_string_as_null(cls, v):
112+
def _parse_empty_string_as_null(cls, v):
114113
"""Safe measure: database entries are sometimes left blank instead of null"""
115114
if isinstance(v, str) and len(v.strip()) == 0:
116115
return None
117116
return v
118117

119118
@field_validator("name", mode="before")
120119
@classmethod
121-
def validate_name(cls, v):
120+
def _validate_name(cls, v):
122121
if v not in FRONTEND_APPS_AVAILABLE:
123122
msg = f"{v} is not in available front-end apps {FRONTEND_APPS_AVAILABLE}"
124123
raise ValueError(msg)

services/web/server/src/simcore_service_webserver/studies_dispatcher/settings.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
from pydantic import TypeAdapter, field_validator, ByteSize
55
from pydantic.fields import Field
66
from pydantic_settings import SettingsConfigDict
7+
8+
from common_library.pydantic_networks_extension import HttpUrlLegacy
79
from servicelib.aiohttp.application_keys import APP_SETTINGS_KEY
810
from settings_library.base import BaseCustomSettings
911

10-
from simcore_service_webserver.studies_dispatcher._rest_handlers import HttpUrlLegacy
11-
1212

1313
class StudiesDispatcherSettings(BaseCustomSettings):
1414
STUDIES_ACCESS_ANONYMOUS_ALLOWED: bool = Field(

0 commit comments

Comments
 (0)