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

OmegaConf.structured raises exception on tuple #973

Closed
jieru-hu opened this issue Jul 12, 2022 · 1 comment · Fixed by #977
Closed

OmegaConf.structured raises exception on tuple #973

jieru-hu opened this issue Jul 12, 2022 · 1 comment · Fixed by #977
Assignees
Labels
bug Something isn't working

Comments

@jieru-hu
Copy link
Collaborator

jieru-hu commented Jul 12, 2022

This seems to be a regression. Although we do not officially support tuple, we should probably still keep supporting this for backward compatibility.

to repro

from dataclasses import dataclass
from typing import Optional
from omegaconf import OmegaConf

@dataclass
class Config:
    vision_layers: Optional[tuple] = (3, 6, 4, 3)

print(OmegaConf.structured(Config))

on OC 2.1.1

 % python repro.py
{'vision_layers': [3, 6, 4, 3]}

on OC 2.2.2

% python repro.py
Traceback (most recent call last):
  File "/Users/jieru/workspace/hydra/repro/repro.py", line 9, in <module>
    print(OmegaConf.structured(Config))
  File "/Users/jieru/miniconda3/envs/hydra39/lib/python3.9/site-packages/omegaconf/omegaconf.py", line 123, in structured
    return OmegaConf.create(obj, parent, flags)
  File "/Users/jieru/miniconda3/envs/hydra39/lib/python3.9/site-packages/omegaconf/omegaconf.py", line 176, in create
    return OmegaConf._create_impl(
  File "/Users/jieru/miniconda3/envs/hydra39/lib/python3.9/site-packages/omegaconf/omegaconf.py", line 882, in _create_impl
    format_and_raise(node=None, key=None, value=None, msg=str(e), cause=e)
  File "/Users/jieru/miniconda3/envs/hydra39/lib/python3.9/site-packages/omegaconf/_utils.py", line 793, in format_and_raise
    _raise(ex, cause)
  File "/Users/jieru/miniconda3/envs/hydra39/lib/python3.9/site-packages/omegaconf/_utils.py", line 771, in _raise
    raise ex.with_traceback(sys.exc_info()[2])  # set env var OC_CAUSE=1 for full trace
  File "/Users/jieru/miniconda3/envs/hydra39/lib/python3.9/site-packages/omegaconf/omegaconf.py", line 843, in _create_impl
    return DictConfig(
  File "/Users/jieru/miniconda3/envs/hydra39/lib/python3.9/site-packages/omegaconf/dictconfig.py", line 111, in __init__
    format_and_raise(node=None, key=key, value=None, cause=ex, msg=str(ex))
  File "/Users/jieru/miniconda3/envs/hydra39/lib/python3.9/site-packages/omegaconf/_utils.py", line 793, in format_and_raise
    _raise(ex, cause)
  File "/Users/jieru/miniconda3/envs/hydra39/lib/python3.9/site-packages/omegaconf/_utils.py", line 771, in _raise
    raise ex.with_traceback(sys.exc_info()[2])  # set env var OC_CAUSE=1 for full trace
  File "/Users/jieru/miniconda3/envs/hydra39/lib/python3.9/site-packages/omegaconf/dictconfig.py", line 94, in __init__
    self._set_value(content, flags=flags)
  File "/Users/jieru/miniconda3/envs/hydra39/lib/python3.9/site-packages/omegaconf/dictconfig.py", line 649, in _set_value
    raise e
  File "/Users/jieru/miniconda3/envs/hydra39/lib/python3.9/site-packages/omegaconf/dictconfig.py", line 646, in _set_value
    self._set_value_impl(value, flags)
  File "/Users/jieru/miniconda3/envs/hydra39/lib/python3.9/site-packages/omegaconf/dictconfig.py", line 676, in _set_value_impl
    data = get_structured_config_data(value, allow_objects=ao)
  File "/Users/jieru/miniconda3/envs/hydra39/lib/python3.9/site-packages/omegaconf/_utils.py", line 481, in get_structured_config_data
    return get_dataclass_data(obj, allow_objects=allow_objects)
  File "/Users/jieru/miniconda3/envs/hydra39/lib/python3.9/site-packages/omegaconf/_utils.py", line 409, in get_dataclass_data
    format_and_raise(
  File "/Users/jieru/miniconda3/envs/hydra39/lib/python3.9/site-packages/omegaconf/_utils.py", line 873, in format_and_raise
    _raise(ex, cause)
  File "/Users/jieru/miniconda3/envs/hydra39/lib/python3.9/site-packages/omegaconf/_utils.py", line 771, in _raise
    raise ex.with_traceback(sys.exc_info()[2])  # set env var OC_CAUSE=1 for full trace
  File "/Users/jieru/miniconda3/envs/hydra39/lib/python3.9/site-packages/omegaconf/_utils.py", line 401, in get_dataclass_data
    d[name] = _maybe_wrap(
  File "/Users/jieru/miniconda3/envs/hydra39/lib/python3.9/site-packages/omegaconf/omegaconf.py", line 1070, in _maybe_wrap
    return _node_wrap(
  File "/Users/jieru/miniconda3/envs/hydra39/lib/python3.9/site-packages/omegaconf/omegaconf.py", line 1052, in _node_wrap
    raise ValidationError(f"Unexpected object type: {type_str(ref_type)}")
omegaconf.errors.ValidationError: Unexpected object type: tuple
    full_key: vision_layers
    object_type=Config

@jieru-hu jieru-hu added the bug Something isn't working label Jul 12, 2022
@jieru-hu
Copy link
Collaborator Author

cc @pixelb @Jasha10 this is blocking internal upgrade

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants