Skip to content

Preserve nested dataclass targets during instantiation#3251

Open
omry wants to merge 1 commit into
mainfrom
pr3251
Open

Preserve nested dataclass targets during instantiation#3251
omry wants to merge 1 commit into
mainfrom
pr3251

Conversation

@omry

@omry omry commented Jun 30, 2026

Copy link
Copy Markdown
Collaborator

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

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
Copilot AI review requested due to automatic review settings June 30, 2026 12:08
@meta-cla meta-cla 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 Jun 30, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 into DictConfig/ListConfig for _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.

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.

[Bug] instantiate: top-level _target_ has inconsistent behavior with _convert_

2 participants