Skip to content

help message of sub model in basesetting do not show the proper default value if the top field has a default #362

Closed
@braindevices

Description

@braindevices
class SubModel(BaseModel):
    v1: str = "default"
    v2: bytes = b"hello"
    v3: int

class Settings(BaseSettings):
    model_config = SettingsConfigDict(
        cli_prog_name="prog1",
        cli_parse_args=True,
        env_prefix="MYTEST_")

    v0: str = "ok"
    sub_model: SubModel = SubModel(v1="top default", v3=3)

sys.argv = [
        'example.py',
        "-h"
    ]
Settings()

It show help:

...
  --sub_model.v1 str    (default: default)
  --sub_model.v2 bytes  (default: b'hello')
  --sub_model.v3 int    (required)

This is apparently wrong, because the default values:

sys.argv = [
        'example.py',
    ]
print(Settings())
#> v0='ok' sub_model=SubModel(v1='top default', v2=b'hello', v3=3)

The help message should use the actual top level default values instead of the sub model's own default values.

We expect:

...
  --sub_model.v1 str    (default: top default)
  --sub_model.v2 bytes  (default: b'hello')
  --sub_model.v3 int    (default: 3)

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions