Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
carmocca opened this issue Mar 9, 2024 · 2 comments · Fixed by #471
Closed

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

carmocca opened this issue Mar 9, 2024 · 2 comments · Fixed by #471
Labels
bug Something isn't working

Comments

@carmocca
Copy link
Contributor

carmocca commented Mar 9, 2024

🐛 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

@carmocca carmocca added the bug Something isn't working label Mar 9, 2024
@carmocca
Copy link
Contributor Author

carmocca commented Mar 9, 2024

Given that

class Thing:
    def __init__(self, foo=1, bar=2):
        print(locals())

from jsonargparse import CLI
CLI(Thing)
foo: 123
bar: 321

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

Works as expected, I would expect these two approaches to produce the same result

@mauvilsa
Copy link
Member

Thank you for reporting! This is fixed with #471.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants