Repository: omry/omegaconf

Issue:
Creating a DictConfig from another drops node types
test:

```
@dataclass
class User:
    name: str
    age: int

cfg1 = OmegaConf.create(module.User(name="James Bond", age=7))
with pytest.raises(ValidationError):
  cfg1.age = "not a number"

cfg2 = OmegaConf.create(cfg1)
with pytest.raises(ValidationError):
  cfg2.age = "not a number"
```

Discussion:

Patch:
diff --git a/news/252.bugix b/news/252.bugix
new file mode 100644
index 0000000..3aade21
--- /dev/null
+++ b/news/252.bugix
@@ -0,0 +1,1 @@
+Fix DictConfig created from another DictConfig drops node types
diff --git a/omegaconf/dictconfig.py b/omegaconf/dictconfig.py
index 5499a5b..aef92ee 100644
--- a/omegaconf/dictconfig.py
+++ b/omegaconf/dictconfig.py
@@ -552,7 +552,7 @@ class DictConfig(BaseContainer, MutableMapping[str, Any]):
                 self._metadata.object_type = get_type_of(value)
             elif isinstance(value, DictConfig):
                 self._metadata.object_type = dict
-                for k, v in value.items_ex(resolve=False):
+                for k, v in value.__dict__["_content"].items():
                     self.__setitem__(k, v)
                 self.__dict__["_metadata"] = copy.deepcopy(value._metadata)
 


Test patch:
diff --git a/tests/structured_conf/test_structured_config.py b/tests/structured_conf/test_structured_config.py
index 73d446d..25b9f73 100644
--- a/tests/structured_conf/test_structured_config.py
+++ b/tests/structured_conf/test_structured_config.py
@@ -800,3 +800,13 @@ class TestDictSubclass:
             module: Any = import_module(class_type)
             with pytest.raises(KeyValidationError):
                 OmegaConf.structured(module.DictSubclass.Error.User2Str())
+
+    def test_construct_from_another_retain_node_types(self, class_type: str) -> None:
+        module: Any = import_module(class_type)
+        cfg1 = OmegaConf.create(module.User(name="James Bond", age=7))
+        with pytest.raises(ValidationError):
+            cfg1.age = "not a number"
+
+        cfg2 = OmegaConf.create(cfg1)
+        with pytest.raises(ValidationError):
+            cfg2.age = "not a number"