Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix int full key when deep copying in instantiate #3019

Merged
merged 1 commit into from
Feb 4, 2025
Merged

Conversation

jesszzzz
Copy link
Contributor

@jesszzzz jesszzzz commented Feb 3, 2025

Motivation

Was seeing an error like this when the full config is a list:

hydra/_internal/instantiate/_instantiate2.py", line 161, in _deep_copy_full_config
    full_key = full_key[: -len(str(index))] + f"[{index}]"
TypeError: 'int' object is not subscriptable

This fixes it by typecasting to a string, and adds a test to avoid future instances

Have you read the Contributing Guidelines on pull requests?

Yes

Test Plan

new unittest passes

Related Issues and PRs

(Is this PR part of a group of changes? Link the other relevant PRs and Issues here. Use https://help.github.com/en/articles/closing-issues-using-keywords for help on GitHub syntax)

@jesszzzz jesszzzz self-assigned this Feb 3, 2025
@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Feb 3, 2025
@@ -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:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the new condition is the same as not full_key. is there a specific scenario you cannot use not full_key?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yeah that's another bug I forgot to mention in the summary, if it's the first item of a list, full_key is 0 so we can't use not full_key

Copy link

@tonykao8080 tonykao8080 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@jesszzzz jesszzzz merged commit fb3a0be into main Feb 4, 2025
24 checks passed
@jesszzzz jesszzzz deleted the fix_int_full_key branch February 4, 2025 15:39
michaelriedl pushed a commit to michaelriedl/hydra that referenced this pull request Feb 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants