coveralls: ## Pull Request Test Coverage Report for [Build 256](https://coveralls.io/builds/26766909)

* **4** of **4**   **(100.0%)**  changed or added relevant lines in **2** files are covered.
* No unchanged relevant lines lost coverage.
* Overall coverage decreased (**-0.08%**) to **99.19%**

---



|  Totals | [![Coverage Status](https://coveralls.io/builds/26766909/badge)](https://coveralls.io/builds/26766909) |
| :-- | --: |
| Change from base [Build 254](https://coveralls.io/builds/26734871): |  -0.08% |
| Covered Lines: | 2449 |
| Relevant Lines: | 2469 |

---
##### 💛  - [Coveralls](https://coveralls.io)

diff --git a/omegaconf/config.py b/omegaconf/config.py
index 0a8995d..a1b3f14 100644
--- a/omegaconf/config.py
+++ b/omegaconf/config.py
@@ -83,6 +83,13 @@ class Config(object):
         assert value is None or isinstance(value, bool)
         self.__dict__['flags'][flag] = value
 
+    def _get_node_flag(self, flag):
+        """
+        :param flag: flag to inspect
+        :return: the state of the flag on this node.
+        """
+        return self.__dict__['flags'][flag]
+
     def _get_flag(self, flag):
         """
         Returns True if this config node flag is set
diff --git a/omegaconf/omegaconf.py b/omegaconf/omegaconf.py
index 03e908b..df3a92b 100644
--- a/omegaconf/omegaconf.py
+++ b/omegaconf/omegaconf.py
@@ -228,7 +228,8 @@ def flag_override(config, name, value):
 # noinspection PyProtectedMember
 @contextmanager
 def read_write(config):
-    prev_state = OmegaConf.is_readonly(config)
+    # noinspection PyProtectedMember
+    prev_state = config._get_node_flag("readonly")
     try:
         OmegaConf.set_readonly(config, False)
         yield config
@@ -238,7 +239,8 @@ def read_write(config):
 
 @contextmanager
 def open_dict(config):
-    prev_state = OmegaConf.is_struct(config)
+    # noinspection PyProtectedMember
+    prev_state = config._get_node_flag("struct")
     try:
         OmegaConf.set_struct(config, False)
         yield config

open_dict change value to the inherited value
for a nested config:
```yaml
foo:
  bar:
    baz: 10
```
if foo is struct, and we do
```python
with open_dict(cfg.foo.bar):
   bar.baz = 20
```

the struct flag of foo.bar would be changed to True.
diff --git a/tests/test_base_config.py b/tests/test_base_config.py
index 713ff52..b7112ed 100644
--- a/tests/test_base_config.py
+++ b/tests/test_base_config.py
@@ -275,3 +275,19 @@ def test_struct_override(src, func, expectation):
     with does_not_raise():
         with open_dict(c):
             func(c)
+
+
+@pytest.mark.parametrize("flag_name,ctx", [("struct", open_dict), ("readonly", read_write)])
+def test_open_dict_restore(flag_name, ctx):
+    """
+    Tests that internal flags are restored properly when applying context on a child node
+    """
+    cfg = OmegaConf.create({"foo": {"bar": 10}})
+    cfg._set_flag(flag_name, True)
+    assert cfg._get_node_flag(flag_name)
+    assert not cfg.foo._get_node_flag(flag_name)
+    with ctx(cfg.foo):
+        cfg.foo.bar = 20
+    assert cfg._get_node_flag(flag_name)
+    assert not cfg.foo._get_node_flag(flag_name)
+

pip install -e .
parse_log_pytest
pytest
pytest coveralls sphinx
apt-get update apt-get install -y gcc
3.6
pytest --no-header -rA --tb=line --color=no -p no:cacheprovider -W ignore::DeprecationWarning
alabaster==0.7.13
attrs @ file:///opt/conda/conda-bld/attrs_1642510447205/work
Babel==2.11.0
certifi==2021.5.30
charset-normalizer==2.0.12
coverage==6.2
coveralls==3.3.1
docopt==0.6.2
docutils==0.18.1
idna==3.10
imagesize==1.4.1
importlib-metadata @ file:///tmp/build/80754af9/importlib-metadata_1631916693255/work
iniconfig @ file:///home/linux1/recipes/ci/iniconfig_1610983019677/work
Jinja2==3.0.3
MarkupSafe==2.0.1
more-itertools @ file:///tmp/build/80754af9/more-itertools_1637733554872/work
-e git+https://github.com/omry/omegaconf.git@db110e3b6effc337fb2dc11fe27b62f24b2f49c2#egg=omegaconf
packaging @ file:///tmp/build/80754af9/packaging_1637314298585/work
pluggy @ file:///tmp/build/80754af9/pluggy_1615976315926/work
py @ file:///opt/conda/conda-bld/py_1644396412707/work
Pygments==2.14.0
pyparsing @ file:///tmp/build/80754af9/pyparsing_1635766073266/work
pytest==6.2.4
pytz==2025.2
PyYAML==6.0.1
requests==2.27.1
six==1.17.0
snowballstemmer==2.2.0
Sphinx==5.3.0
sphinxcontrib-applehelp==1.0.2
sphinxcontrib-devhelp==1.0.2
sphinxcontrib-htmlhelp==2.0.0
sphinxcontrib-jsmath==1.0.1
sphinxcontrib-qthelp==1.0.3
sphinxcontrib-serializinghtml==1.1.5
toml @ file:///tmp/build/80754af9/toml_1616166611790/work
typing_extensions @ file:///opt/conda/conda-bld/typing_extensions_1647553014482/work
urllib3==1.26.20
zipp @ file:///tmp/build/80754af9/zipp_1633618647012/work

name: omegaconf
channels:
  - defaults
  - https://repo.anaconda.com/pkgs/main
  - https://repo.anaconda.com/pkgs/r
  - conda-forge
dependencies:
  - _libgcc_mutex=0.1=main
  - _openmp_mutex=5.1=1_gnu
  - attrs=21.4.0=pyhd3eb1b0_0
  - ca-certificates=2025.2.25=h06a4308_0
  - certifi=2021.5.30=py36h06a4308_0
  - importlib-metadata=4.8.1=py36h06a4308_0
  - importlib_metadata=4.8.1=hd3eb1b0_0
  - iniconfig=1.1.1=pyhd3eb1b0_0
  - ld_impl_linux-64=2.40=h12ee557_0
  - libffi=3.3=he6710b0_2
  - libgcc-ng=11.2.0=h1234567_1
  - libgomp=11.2.0=h1234567_1
  - libstdcxx-ng=11.2.0=h1234567_1
  - more-itertools=8.12.0=pyhd3eb1b0_0
  - ncurses=6.4=h6a678d5_0
  - openssl=1.1.1w=h7f8727e_0
  - packaging=21.3=pyhd3eb1b0_0
  - pip=21.2.2=py36h06a4308_0
  - pluggy=0.13.1=py36h06a4308_0
  - py=1.11.0=pyhd3eb1b0_0
  - pyparsing=3.0.4=pyhd3eb1b0_0
  - pytest=6.2.4=py36h06a4308_2
  - python=3.6.13=h12debd9_1
  - readline=8.2=h5eee18b_0
  - setuptools=58.0.4=py36h06a4308_0
  - sqlite=3.45.3=h5eee18b_0
  - tk=8.6.14=h39e8969_0
  - toml=0.10.2=pyhd3eb1b0_0
  - typing_extensions=4.1.1=pyh06a4308_0
  - wheel=0.37.1=pyhd3eb1b0_0
  - xz=5.6.4=h5eee18b_1
  - zipp=3.6.0=pyhd3eb1b0_0
  - zlib=1.2.13=h5eee18b_1
  - pip:
      - alabaster==0.7.13
      - babel==2.11.0
      - charset-normalizer==2.0.12
      - coverage==6.2
      - coveralls==3.3.1
      - docopt==0.6.2
      - docutils==0.18.1
      - idna==3.10
      - imagesize==1.4.1
      - jinja2==3.0.3
      - markupsafe==2.0.1
      - pygments==2.14.0
      - pytz==2025.2
      - pyyaml==6.0.1
      - requests==2.27.1
      - six==1.17.0
      - snowballstemmer==2.2.0
      - sphinx==5.3.0
      - sphinxcontrib-applehelp==1.0.2
      - sphinxcontrib-devhelp==1.0.2
      - sphinxcontrib-htmlhelp==2.0.0
      - sphinxcontrib-jsmath==1.0.1
      - sphinxcontrib-qthelp==1.0.3
      - sphinxcontrib-serializinghtml==1.1.5
      - urllib3==1.26.20
prefix: /opt/conda/envs/omegaconf

tests/test_base_config.py::test_open_dict_restore[struct-open_dict] tests/test_base_config.py::test_open_dict_restore[readonly-read_write]
tests/test_base_config.py::test_set_value[input_0-foo-10-expected0] tests/test_base_config.py::test_set_value[input_1-foo-value1-expected1] tests/test_base_config.py::test_set_value[input_2-foo-value2-expected2] tests/test_base_config.py::test_set_value[input_3-foo-value3-expected3] tests/test_base_config.py::test_set_value[input_4-0-10-expected4] tests/test_base_config.py::test_set_value[input_5-1-10-expected5] tests/test_base_config.py::test_set_value[input_6-1-value6-expected6] tests/test_base_config.py::test_set_value[input_7-1-value7-expected7] tests/test_base_config.py::test_set_value[input_8-1-value8-expected8] tests/test_base_config.py::test_set_value_validation_fail[input_0-foo-str] tests/test_base_config.py::test_set_value_validation_fail[input_1-1-str] tests/test_base_config.py::test_to_container_returns_primitives[input_0] tests/test_base_config.py::test_to_container_returns_primitives[input_1] tests/test_base_config.py::test_to_container_returns_primitives[input_2] tests/test_base_config.py::test_to_container_returns_primitives[input_3] tests/test_base_config.py::test_to_container_returns_primitives[input_4] tests/test_base_config.py::test_empty[input_0-True] tests/test_base_config.py::test_empty[input_1-True] tests/test_base_config.py::test_empty[input_2-False] tests/test_base_config.py::test_empty[input_3-False] tests/test_base_config.py::test_repr[input_0] tests/test_base_config.py::test_repr[input_1] tests/test_base_config.py::test_repr[input_2] tests/test_base_config.py::test_repr[input_3] tests/test_base_config.py::test_repr[input_4] tests/test_base_config.py::test_repr[input_5] tests/test_base_config.py::test_repr[input_6] tests/test_base_config.py::test_str[input_0] tests/test_base_config.py::test_str[input_1] tests/test_base_config.py::test_str[input_2] tests/test_base_config.py::test_str[input_3] tests/test_base_config.py::test_str[input_4] tests/test_base_config.py::test_str[input_5] tests/test_base_config.py::test_str[input_6] tests/test_base_config.py::test_flag_dict[readonly] tests/test_base_config.py::test_flag_dict[struct] tests/test_base_config.py::test_freeze_nested_dict[readonly] tests/test_base_config.py::test_freeze_nested_dict[struct] tests/test_base_config.py::test_deepcopy[src0] tests/test_base_config.py::test_deepcopy[src1] tests/test_base_config.py::test_deepcopy[src2] tests/test_base_config.py::test_deepcopy[src3] tests/test_base_config.py::test_deepcopy_readonly[src0] tests/test_base_config.py::test_deepcopy_readonly[src1] tests/test_base_config.py::test_deepcopy_readonly[src2] tests/test_base_config.py::test_deepcopy_readonly[src3] tests/test_base_config.py::test_deepcopy_struct[src0] tests/test_base_config.py::test_deepcopy_struct[src1] tests/test_base_config.py::test_deepcopy_struct[src2] tests/test_base_config.py::test_deepcopy_struct[src3] tests/test_base_config.py::test_deepcopy_after_del tests/test_base_config.py::test_deepcopy_with_interpolation tests/test_base_config.py::test_deepcopy_and_merge_and_flags tests/test_base_config.py::test_flag_override[src0-struct-False-<lambda>-expectation0] tests/test_base_config.py::test_flag_override[src1-readonly-False-<lambda>-expectation1] tests/test_base_config.py::test_read_write_override[src0-<lambda>-expectation0] tests/test_base_config.py::test_read_write_override[src1-<lambda>-expectation1] tests/test_base_config.py::test_tokenize_with_escapes[dog,cat-tokenized0] tests/test_base_config.py::test_tokenize_with_escapes[dog\\,cat\\ tests/test_base_config.py::test_tokenize_with_escapes[dog,\\ tests/test_base_config.py::test_tokenize_with_escapes[\\ tests/test_base_config.py::test_tokenize_with_escapes[dog, tests/test_base_config.py::test_tokenize_with_escapes[whitespace\\ tests/test_base_config.py::test_tokenize_with_escapes[None-tokenized8] tests/test_base_config.py::test_tokenize_with_escapes[-tokenized9] tests/test_base_config.py::test_tokenize_with_escapes[no tests/test_base_config.py::test_struct_override[src0-<lambda>-expectation0]
omegaconf/config.py omegaconf/omegaconf.py
omegaconf/config.py omegaconf/omegaconf.py