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

Merge Option of update function does not merge list #1154

Open
mschwab12 opened this issue Feb 21, 2024 · 1 comment
Open

Merge Option of update function does not merge list #1154

mschwab12 opened this issue Feb 21, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@mschwab12
Copy link

Describe the bug
I want to update a list config an use the merge option (#367) as I want to add another list item.
When I do this the existing list item always gets replaced instead of merged which is because in the code of _list_merge of basecontainer.py the temp dest gets initialised with an empty list, gets the new value added and then the original list is replaced with the temp list. So this of course does not make a match. I am not sure if this behaviour is intended.

To Reproduce

from omegaconf import OmegaConf

cfg = OmegaConf.create({"a": {"b": [10]}})
print(OmegaConf.to_yaml(cast(OmegaConfig, cfg)))
OmegaConf.update(cfg, "a.b", [20])
print(OmegaConf.to_yaml(cast(OmegaConfig, cfg)))

# Outputs
# a:
#   b:
#   - 10
#
# a:
#   b:
#   - 20

Expected behavior
Output should be:

# Outputs
# a:
#   b:
#   - 10
#
# a:
#   b:
#   - 10
#   - 20

Additional context

  • OmegaConf version: 2.3.0
  • Python version: 3.10.12
  • Operating system: macOS 14.2.1
@mschwab12 mschwab12 added the bug Something isn't working label Feb 21, 2024
@odelalleau
Copy link
Collaborator

This is because merging lists in OmegaConf leads to the merged list overriding the previous one. So this is actually working as intended.

You can check this comment for pointers towards potential workarounds: facebookresearch/hydra#1547 (comment)

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

No branches or pull requests

2 participants