Open MatteoVoges opened 11 months ago
Although I agree this can be confusing, I'm not sure this is actually a bug.
The way flags work in OmegaConf is that a node inherits its parent's flags except for those that are explicitly set for this node. See code at: https://github.com/omry/omegaconf/blob/7dae67e4a3869b584fd6d6408b2f916c176755db/omegaconf/base.py#L200
The order in which flags are set doesn't matter. Whether you do
OmegaConf.set_readonly(config, False)
OmegaConf.set_readonly(config.a, True)
or
OmegaConf.set_readonly(config.a, True)
OmegaConf.set_readonly(config, False)
you will always have is_readonly(config.a)
because the flag is explicitly set for the subconfig node.
I think it'd make sense to add an option to override the child nodes' flags, but in the meantime, my suggestion would be that you write your own function that iterates over children to achieve this.
Thanks for the explanation. I just thought that the behavior should be the same, regardless if the value of the flag gets set to True
or False
.
Because I just need a "reset" of the flag for the whole config and some child nodes can be readonly
, I just used oc.create(oc.to_container(config))
and create a fresh config without any flags.
Thanks for the explanation. I just thought that the behavior should be the same, regardless if the value of the flag gets set to
True
orFalse
.
It should indeed be the same.
Because I just need a "reset" of the flag for the whole config and some child nodes can be
readonly
, I just usedoc.create(oc.to_container(config))
and create a fresh config without any flags.
I agree it'd be good to also have a way to clear flags recursively.
It should indeed be the same.
Ahh you're right. I forgot for a moment, that directly set flags have higher priority than the parent flags :man_facepalming: .
Because I just need a "reset" of the flag for the whole config and some child nodes can be readonly, I just used oc.create(oc.to_container(config)) and create a fresh config without any flags.
IIRC You can reset the value of a node by setting the flag value on that node to None. If you want to do it recursively, maybe it's better to introduce a new reset_flag function instead of overloading set_flag.
I would be happy with both options. I just need a config with no flags, therefor its not important, if the value is None
or False
. A reset_flag
function would be cool, too, but would do the same job as set_flag("reaonly", None)
.
Yeah I think a recursive set_flag()
is more generic and powerful than a recursive reset_flag()
.
To be honest, I think set_flag with a recursive flag is more confusing. The semantics of set_flag are already recursive, so to a user reading the doc it would be unclear what recursive=True is doing differently. In addition, setting the flag recursively will "freeze" the flag on the whole subtree and subsequent calls setting the flag on the parent will no longer be recursive as they are now (unless recursive=True) is passed.
Describe the bug There is unexpected behavior for different types of recursive flag passing when using
OmegaConf.set_readonly()
To Reproduce
Here we see in the first example, that when applying
readonly
to a config, that subconfigs get recursively updated with the correct state. In the second example we applyreadonly
to a subconfig, and the parent node doesn't get updated, but when settingreadonly
to false in the parent node, the children don't get recursively updated, which is wrong.Expected behavior The child nodes should get correctly updated.
Additional context