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

unsafe_merge: detect value with no root #1088

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Conversation

Jasha10
Copy link
Collaborator

@Jasha10 Jasha10 commented Jun 11, 2023

Closes #1087.

This PR addresses an edge-case where AssertionError is raised during a
call to OmegaConf.unsafe_merge.

This PR is marked as a draft:

  • I haven't written tests yet
  • I'm not sure if this is the best approach to solving the issue.

This PR addresses an edge-case where `AssertionError` is raised during a
call to `OmegaConf.unsafe_merge`.

This PR is marked as a draft:
- I haven't written tests yet
- I'm not sure if this is the best approach to solving the issue.
Comment on lines +534 to +539
# Detect the special case where value has no root:
value_has_root = (
isinstance(value, Container) or value._get_parent() is not None
)
# if value is from the same config, perform a deepcopy no matter what.
if self._get_root() is value._get_root():
if value_has_root and self._get_root() is value._get_root():
Copy link
Collaborator Author

@Jasha10 Jasha10 Jun 11, 2023

Choose a reason for hiding this comment

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

Normally, every node should have a root. The "root" of a node is a top-level Container that owns the node. In other words, the root is the top of the config tree. You can get the root of a node by calling node._get_root().

In example from issue #1087, the above call to value._get_root() raises an AssertionError. This happens because value is a temporary UnionNode value that has no parent (and thus has no root).

Here is a potential alternative approach to solving issue #1087:
Instead of detecting whether value_has_root as above, we could modify the Node._get_root method to return an Optional[Container] instead of a Container.

Copy link
Owner

Choose a reason for hiding this comment

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

Both approaches seems okay to me.
Also, please add a test for unsafe_merge similar in this case (similar to the repro in the bug report).

Copy link
Owner

Choose a reason for hiding this comment

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

Make sure that your proposed logic does not treat the nodes as being from the same config (see comment in 538).

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I've added the test.

Make sure that your proposed logic does not treat the nodes as being from the same config

Yup. If value_has_root is False then value is a temporary node and does not come from the same config as self.

@Jasha10 Jasha10 marked this pull request as ready for review June 22, 2023 18:35
@mohammad7t
Copy link

Hi @omry ,

Thank you for creating this PR. I'm wondering if there is any blocker for merging this PR, that I could potentially help resolving?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

unsafe_merge crashes with nested structured config and union type
3 participants