Using validation_alias
with a BaseSettings
class does the trick!
class WorkflowRun(BaseSettings):
id: str
name: str
node: str = Field(validation_alias=AliasChoices('node', 'ENV_NODE_POOL'))
model_config = SettingsConfigDict(
env_file=".env",
env_file_encoding="utf-8",
extra="ignore",
env_ignore_empty=True,
populate_by_name=True,
)
Invocations:
>>> WorkflowRun(**{
"id": "1",
"name": "test",
})
WorkflowRun(id='1', name='test', node='default-node')
>>> WorkflowRun(**{
"id": "1",
"name": "test",
"node": "new-pool"})
WorkflowRun(id='1', name='test', node='new-pool')