Conversation
Preserve dataclass instances returned by nested _target_ entries when _convert_=none inserts them into DictConfig or ListConfig containers. Add regression coverage for nested dict and list containers, including top-level list roots. Fixes #2507
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes an instantiation edge case where dataclass instances produced by nested _target_ configs could be coerced back into structured DictConfig/ListConfig nodes when _convert_=none returns OmegaConf containers. It does so by explicitly wrapping structured-config objects as AnyNode before inserting them into DictConfig/ListConfig, preserving the instantiated object.
Changes:
- Wrap structured-config (e.g., dataclass) instances in
AnyNode(…, allow_objects=True)when inserting intoDictConfig/ListConfigfor_convert_=none. - Add regression tests covering nested dict/list containers, including a top-level list root case.
- Add a news fragment and update isort to skip
.venv.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
hydra/_internal/instantiate/_instantiate2.py |
Preserve structured-config instances in _convert_=none containers by wrapping them as AnyNode before insertion. |
tests/instantiate/test_instantiate.py |
Updates expected ConvertMode.NONE behavior and adds regression coverage for nested dataclass targets in dict/list containers. |
news/2507.bugfix |
User-facing bugfix note for the instantiation behavior change. |
.isort.cfg |
Exclude .venv from isort processing. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Preserve dataclass instances returned by nested target entries when convert=none inserts them into DictConfig or ListConfig containers. Add regression coverage for nested dict and list containers, including top-level list roots.
Fixes #2507