-
Notifications
You must be signed in to change notification settings - Fork 98
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
ValidationError for Unions in nested Dicts using merge with structured config #1166
Open
4 tasks done
Labels
Comments
I found another few examples. Here with a from dataclasses import dataclass, field
from typing import Union
from omegaconf import OmegaConf
@dataclass
# Default is z.a.b = 1
class HasUnion:
z: dict[str, list[Union[str, int]]] = field(
default_factory=lambda: {"a": [1,2]}
)
# z.a = [1] (This works)
# z.c = [1] (This doesn't work)
cfg = OmegaConf.merge(
OmegaConf.structured(HasUnion),
OmegaConf.create("""
z:
c:
- 1
""")
) And here with a from dataclasses import dataclass, field
from omegaconf import OmegaConf
@dataclass
class Foo:
exist1: int
exist2: str
@dataclass
class BaseStructure:
z: dict[str, list[Foo]] = field(
default_factory=lambda: {"a": [Foo(1, "lol")]}
)
cfg = OmegaConf.merge(
OmegaConf.structured(BaseStructure),
OmegaConf.create("""
z:
c:
- exist1: 1
dontexist2: lol
""")
) EDIT: I accidentally clicked on close, sry. |
Thanks for the bug report, @denialofsandwich. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Describe the bug
The validation of unions, which are nested in a dict seems to be broken and throws a ValidationError during a merge, even if the types should be correct.
To Reproduce
The last line is throwing the ValidationError:
This is the exception thwown at the last line:
Expected behavior
I expect
z.c.b = 1
not to fail, since1
is a valid type ofUnion[str, int]
and if the Union is not nested inside a dict.Additional context
The text was updated successfully, but these errors were encountered: