Skip to content

Overriding a config's argument makes everything else fall back to the base class #464

@carmocca

Description

@carmocca

🐛 Bug report

To reproduce

repro.py:

from dataclasses import dataclass
from typing import Optional

@dataclass
class Thing:
    foo: int = 1
    bar: int = 2

def fn(thing: Optional[Thing] = None):
    thing = Thing() if thing is None else thing
    print(thing)

from jsonargparse import CLI
CLI(fn)

repro.yaml:

thing:
  foo: 123
  bar: 321

python repro.py --config repro.yaml --thing.foo 9

Expected behavior

The above prints

Thing(foo=9, bar=2)

but I expected

Thing(foo=9, bar=321)

Context

A more real world example is that you have a trainer_config.yaml and you want to only modify the --train.max_epochs value without having everything else fall back to dataclass defaults

Environment

Version 4.275

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions