44
55import osparc
66from packaging .version import InvalidVersion , Version
7- from pydantic import BaseModel , field_validator , SecretStr
7+ from pydantic import BaseModel , SecretStr , field_validator
88from pydantic_settings import BaseSettings , SettingsConfigDict
99
1010# Holds classes for passing data around between scripts.
@@ -20,7 +20,9 @@ class ServerSettings(BaseSettings):
2020 model_config = SettingsConfigDict (env_prefix = "osparc_api_" )
2121
2222 def __hash__ (self ):
23- return hash (self .host + self .key .get_secret_value () + self .secret .get_secret_value ())
23+ return hash (
24+ self .host + self .key .get_secret_value () + self .secret .get_secret_value ()
25+ )
2426
2527 def __eq__ (self , other ):
2628 return (
@@ -114,9 +116,19 @@ def write_to_file(self, pth: Path = Path() / "pytest.ini") -> None:
114116 """Generate the pytest.ini file"""
115117 pth .unlink (missing_ok = True )
116118 pth .parent .mkdir (exist_ok = True )
119+
117120 config : configparser .ConfigParser = configparser .ConfigParser ()
121+
118122 for field_name in self .model_fields :
119123 model : BaseModel = getattr (self , field_name )
120- config [field_name ] = model .model_dump (exclude_none = True )
124+ # WARNING: this is a temporary solution until we learn how to customize
125+ # the serialization used in model_dump
126+ config [field_name ] = {
127+ name : value .get_secret_value ()
128+ if isinstance (value , SecretStr )
129+ else value
130+ for name , value in model .model_dump (exclude_none = True ).items ()
131+ }
132+
121133 with open (pth , "w" ) as f :
122134 config .write (f )
0 commit comments