@@ -215,18 +215,6 @@ def enable_only_if_dev_features_allowed(cls, v, values, field: ModelField):
215215 log .warning ("%s still under development and will be disabled." , field .name )
216216 return None if field .allow_none else False
217217
218- class Config (BaseCustomSettings .Config ):
219- # NOTE: FutureWarning: aliases are no longer used by BaseSettings to define which environment variables to read.
220- # Instead use the "env" field setting. See https://pydantic-docs.helpmanual.io/usage/settings/#environment-variable-names
221- # NOTE: These alias are ONLY used in export, not in constructor
222- fields = {
223- "SC_VCS_URL" : "vcs_url" ,
224- "SC_VCS_REF" : "vcs_ref" ,
225- "SC_BUILD_DATE" : "build_date" ,
226- "SWARM_STACK_NAME" : "stack_name" ,
227- }
228- alias_generator = lambda s : s .lower ()
229-
230218 @cached_property
231219 def log_level (self ) -> int :
232220 return getattr (logging , self .WEBSERVER_LOGLEVEL .upper ())
@@ -273,6 +261,31 @@ def _get_disabled_public_plugins(self) -> list[str]:
273261 plugins_disabled .append (field_name )
274262 return plugins_disabled
275263
264+ def _export_by_alias (self , ** kwargs ) -> dict [str , Any ]:
265+ # This is a small helper to assist export functions since aliases are no longer used by
266+ # BaseSettings to define which environment variables to read.
267+ # SEE https://github.com/ITISFoundation/osparc-simcore/issues/3372
268+ #
269+ # NOTE: This is a copy from pydantic's Config.fields and Config.alias_generator
270+ # SEE https://pydantic-docs.helpmanual.io/usage/model_config/#options
271+ # SEE https://pydantic-docs.helpmanual.io/usage/model_config/#alias-generator
272+ #
273+ config_fields = {
274+ "SC_VCS_URL" : "vcs_url" ,
275+ "SC_VCS_REF" : "vcs_ref" ,
276+ "SC_BUILD_DATE" : "build_date" ,
277+ "SWARM_STACK_NAME" : "stack_name" ,
278+ }
279+ config_alias_generator = lambda s : s .lower ()
280+
281+ data = self .dict (** kwargs )
282+ current_keys = list (data .keys ())
283+
284+ for key in current_keys :
285+ if new_key := (config_fields .get (key ) or config_alias_generator (key )):
286+ data [new_key ] = data .pop (key )
287+ return data
288+
276289 def public_dict (self ) -> dict [str , Any ]:
277290 """Data publicaly available"""
278291
@@ -284,7 +297,7 @@ def public_dict(self) -> dict[str, Any]:
284297 data ["login_2fa_required" ] = self .WEBSERVER_LOGIN .LOGIN_2FA_REQUIRED
285298
286299 data .update (
287- self .dict (
300+ self ._export_by_alias (
288301 include = {
289302 "APP_NAME" ,
290303 "API_VERSION" ,
@@ -293,13 +306,12 @@ def public_dict(self) -> dict[str, Any]:
293306 "SC_BUILD_DATE" ,
294307 },
295308 exclude_none = True ,
296- by_alias = True ,
297309 )
298310 )
299311 return data
300312
301313 def to_client_statics (self ) -> dict [str , Any ]:
302- data = self .dict (
314+ data = self ._export_by_alias (
303315 include = {
304316 "APP_NAME" ,
305317 "API_VERSION" ,
@@ -309,7 +321,6 @@ def to_client_statics(self) -> dict[str, Any]:
309321 "SWARM_STACK_NAME" ,
310322 },
311323 exclude_none = True ,
312- by_alias = True ,
313324 )
314325 data ["plugins_disabled" ] = self ._get_disabled_public_plugins ()
315326
0 commit comments