-
Notifications
You must be signed in to change notification settings - Fork 116
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
set_struct does not work in version 2.1.0.dev24 #646
Comments
This has nothing to do with set_struct and is an intentional change. OmegaConf 2.1 will align the behavior of OmegaConf DictConfig with that of plain dict much more, enabling better drop-in-replacement support. One of the breaking changes in OmegaConf 2.1 is that dict You can use one of those alternatives: # dict style access
c1.get("aa") # None
# object style acecss
getattr(c1, "aa", None) # None |
Hmm, it seemed to be related to |
Check #515 for the motivation behind this change and some migration hints. |
Is there any way to restore the previous behavior? It is now a pain to access optional, very nested parameters. Sometimes, I have highly nested configurations, e.g. model:
feature_extractor:
arch: resnet50 The model dict might not be in my configuration. Previous code: if cfg.model.feature_extractor.arch is not None:
do_something(cfg.model.feature_extractor.arch) Code now? if 'model' in cfg and `feature_extractor` in cfg.model and `arch` in cfg.model.feature_extractor`:
do_something(cfg.model.feature_extractor.arch) |
There is no way to get the previous behavior with OmegaConf 2.1. Your example is wrong though, you don't need to check every level, just the last one. In [1]: from omegaconf import *
In [2]: __version__
Out[2]: '2.0.6'
In [3]: cfg = OmegaConf.create()
In [4]: cfg.foo.bar
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-4-c2e7eafeb852> in <module>
----> 1 cfg.foo.bar
AttributeError: 'NoneType' object has no attribute 'bar' The equivalent code is: if "arch" in cfg.model.feature_extractor:
do_something(cfg.model.feature_extractor.arch) |
You actually get what you thought you were getting using select: cfg = OmegaConf.create()
print(OmegaConf.select(cfg, "foo.bar")) # None |
Closing, feel free to follow up if you have more questions. |
Describe the bug
OmegaConf.set_struct(cfg, False)
does not behave as expected.To Reproduce
Traceback
Traceback:
Expected behavior
After running
pip install --upgrade omegaconf==2
, everything works exactly as expected.result:
Additional context
The text was updated successfully, but these errors were encountered: