Skip to content
New issue

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

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

Already on GitHub? # to your account

Nested Containers in structured config type annotation #427

Closed
gibiansky opened this issue Oct 29, 2020 · 2 comments · Fixed by #890
Closed

Nested Containers in structured config type annotation #427

gibiansky opened this issue Oct 29, 2020 · 2 comments · Fixed by #890
Assignees
Labels
enhancement New feature or request priority_high
Milestone

Comments

@gibiansky
Copy link

Describe the bug
Using Dict[str, List[str]] or other similar complex value types fails.

To Reproduce

from dataclasses import dataclass
from typing import Dict, Tuple, List

from omegaconf import OmegaConf, MISSING

@dataclass
class Config:
    # If I change List[str] to the following, same error:
    #   Tuple[str, str]
    #   Tuple[str, ...]
    #   Dict[str, str]
    data: Dict[str, List[str]] = MISSING

# omegaconf.errors.ValidationError: Unsupported value type : typing.List[str]
OmegaConf.structured(Config)

Expected behavior
It should work.

Instead you get Validation error (on 2.0) and the following on master:

Traceback (most recent call last):
  File "test.py", line 15, in <module>
    OmegaConf.structured(Config)
  File "/Users/gibiansky/env/lib/python3.7/site-packages/omegaconf/omegaconf.py", line 145, in structured
    return OmegaConf.create(obj, parent, flags)
  File "/Users/gibiansky/env/lib/python3.7/site-packages/omegaconf/omegaconf.py", line 201, in create
    flags=flags,
  File "/Users/gibiansky/env/lib/python3.7/site-packages/omegaconf/omegaconf.py", line 254, in _create_impl
    flags=flags,
  File "/Users/gibiansky/env/lib/python3.7/site-packages/omegaconf/dictconfig.py", line 105, in __init__
    format_and_raise(node=None, key=None, value=None, cause=ex, msg=str(ex))
  File "/Users/gibiansky/env/lib/python3.7/site-packages/omegaconf/dictconfig.py", line 89, in __init__
    self._set_value(content, flags=flags)
  File "/Users/gibiansky/env/lib/python3.7/site-packages/omegaconf/dictconfig.py", line 552, in _set_value
    raise e
  File "/Users/gibiansky/env/lib/python3.7/site-packages/omegaconf/dictconfig.py", line 549, in _set_value
    self._set_value_impl(value, flags)
  File "/Users/gibiansky/env/lib/python3.7/site-packages/omegaconf/dictconfig.py", line 580, in _set_value_impl
    allow_objects=self._get_flag("allow_objects"),
  File "/Users/gibiansky/env/lib/python3.7/site-packages/omegaconf/_utils.py", line 312, in get_structured_config_data
    return get_dataclass_data(obj, allow_objects=allow_objects)
  File "/Users/gibiansky/env/lib/python3.7/site-packages/omegaconf/_utils.py", line 253, in get_dataclass_data
    parent=dummy_parent,
  File "/Users/gibiansky/env/lib/python3.7/site-packages/omegaconf/omegaconf.py", line 846, in _maybe_wrap
    ref_type=ref_type,
  File "/Users/gibiansky/env/lib/python3.7/site-packages/omegaconf/omegaconf.py", line 777, in _node_wrap
    element_type=element_type,
  File "/Users/gibiansky/env/lib/python3.7/site-packages/omegaconf/dictconfig.py", line 105, in __init__
    format_and_raise(node=None, key=None, value=None, cause=ex, msg=str(ex))
  File "/Users/gibiansky/env/lib/python3.7/site-packages/omegaconf/dictconfig.py", line 77, in __init__
    flags=flags,
  File "<string>", line 10, in __init__
  File "/Users/gibiansky/env/lib/python3.7/site-packages/omegaconf/base.py", line 42, in __post_init__
    assert self.element_type is Any or isinstance(self.element_type, type)
AssertionError

Python 3.7.5 on recent Mac OSX.

@gibiansky gibiansky added the bug Something isn't working label Oct 29, 2020
@omry omry added this to the OmegaConf 2.1 milestone Oct 29, 2020
@omry omry added enhancement New feature or request In progress and removed bug Something isn't working labels Feb 3, 2021
@omry omry removed the In progress label Feb 17, 2021
@omry omry modified the milestones: OmegaConf 2.1, OmegaConf 2.2 Feb 22, 2021
@omry
Copy link
Owner

omry commented Feb 22, 2021

Bouncing this to 2.2, we are wrapping up 2.1.

@Jasha10 Jasha10 changed the title Complex Dict value types fail with exception Nested Containers in structured config type annotation Oct 25, 2021
@Jasha10 Jasha10 self-assigned this Nov 11, 2021
@fxmarty
Copy link

fxmarty commented Apr 13, 2022

@Jasha10 Is there any workaround for this in omegaconf 2.1.1? Typically, I am trying to use a structured config for List[Dict] and fall into the same error. Are simple cases OK, for example List[Tuple[str, List]]?

Edit: just saw this suggestion facebookresearch/hydra#1752 (comment) , I confirm using Any helps.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
enhancement New feature or request priority_high
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants