Skip to content

Commit

Permalink
Fix error when full_key is an int
Browse files Browse the repository at this point in the history
  • Loading branch information
jesszzzz committed Feb 3, 2025
1 parent 7c8fa4a commit e29eefe
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
3 changes: 2 additions & 1 deletion hydra/_internal/instantiate/_instantiate2.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 22 additions & 0 deletions tests/instantiate/test_instantiate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit e29eefe

Please sign in to comment.