diff --git a/hydra/_internal/instantiate/_instantiate2.py b/hydra/_internal/instantiate/_instantiate2.py index bc27918274..98513a9cdf 100644 --- a/hydra/_internal/instantiate/_instantiate2.py +++ b/hydra/_internal/instantiate/_instantiate2.py @@ -151,8 +151,9 @@ def _deep_copy_full_config(subconfig: Any) -> Any: return copy.deepcopy(subconfig) full_key = subconfig._get_full_key(None) - if not full_key: + if full_key == "" or full_key is None: return copy.deepcopy(subconfig) + full_key = str(full_key) if OmegaConf.is_list(subconfig._get_parent()): # OmegaConf has a bug where _get_full_key doesn't add [] if the parent diff --git a/tests/instantiate/test_instantiate.py b/tests/instantiate/test_instantiate.py index 6a89979074..836c34109e 100644 --- a/tests/instantiate/test_instantiate.py +++ b/tests/instantiate/test_instantiate.py @@ -651,6 +651,28 @@ def test_class_instantiate_omegaconf_node(instantiate_func: Any, config: Any) -> assert OmegaConf.is_config(obj.c) +@mark.parametrize( + "src", + [ + ( + ListConfig( + [ + { + "_target_": "tests.instantiate.AClass", + "b": 200, + "c": {"x": 10, "y": "${b}"}, + } + ] + ) + ) + ], +) +def test_class_instantiate_list_item(instantiate_func: Any, config: Any) -> Any: + obj = instantiate_func(config[0], a=10, d=AnotherClass(99))[0] + assert obj == AClass(a=10, b=200, c={"x": 10, "y": 200}, d=AnotherClass(99)) + assert OmegaConf.is_config(obj.c) + + @mark.parametrize("src", [{"_target_": "tests.instantiate.Adam"}]) def test_instantiate_adam(instantiate_func: Any, config: Any) -> None: with raises(