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

[Bug] Optional[List] params defaulted to None don't work #1117

Closed
alexeib opened this issue Nov 3, 2020 · 4 comments · Fixed by #1118
Closed

[Bug] Optional[List] params defaulted to None don't work #1117

alexeib opened this issue Nov 3, 2020 · 4 comments · Fixed by #1118
Labels
bug Something isn't working
Milestone

Comments

@alexeib
Copy link

alexeib commented Nov 3, 2020

see title.
Version: 1.0.3
example:

hydra_ex.py

import hydra

from dataclasses import dataclass, field
from typing import Optional, List
from hydra.core.config_store import ConfigStore

@dataclass
class Config:
    my_field: Optional[List[int]] = None
    other_field: int = 5

cs = ConfigStore.instance()
cs.store(name="hydra_ex", node=Config)

@hydra.main(config_path=".", config_name="hydra_ex")
def main(cfg):
    print(cfg)

main()

hydea_ex.yaml:

# @package _group_
other_field: 42

output:

Cannot iterate a ListConfig object representing None
	full_key: my_field
	reference_type=Optional[List[int]]
	object_type=list

Set the environment variable HYDRA_FULL_ERROR=1 for a complete stack trace.
@alexeib alexeib added the bug Something isn't working label Nov 3, 2020
@omry
Copy link
Collaborator

omry commented Nov 3, 2020

Thanks. can you update the issue with a the complete stack trace?

$ HYDRA_FULL_ERROR=1 python hydra_ex.py

Also, can you mention the Hydra version in the issue. is it 1.0.3?

@omry omry added this to the 1.0.4 milestone Nov 3, 2020
@alexeib
Copy link
Author

alexeib commented Nov 3, 2020

OC_CAUSE=1 HYDRA_FULL_ERROR=1 python hydra_ex.py                                                    14:58:42
Traceback (most recent call last):
  File "/private/home/abaevski/.conda/envs/fairseq-fp16-20200821/lib/python3.6/site-packages/omegaconf/listconfig.py", line 444, in _iter_ex
    raise TypeError("Cannot iterate a ListConfig object representing None")
TypeError: Cannot iterate a ListConfig object representing None

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/private/home/abaevski/.conda/envs/fairseq-fp16-20200821/lib/python3.6/site-packages/hydra/_internal/config_loader_impl.py", line 156, in load_configuration
    from_shell=from_shell,
  File "/private/home/abaevski/.conda/envs/fairseq-fp16-20200821/lib/python3.6/site-packages/hydra/_internal/config_loader_impl.py", line 236, in _load_configuration
    _recursive_unset_readonly(hydra_cfg)
  File "/private/home/abaevski/.conda/envs/fairseq-fp16-20200821/lib/python3.6/site-packages/hydra/_internal/config_loader_impl.py", line 911, in _recursive_unset_readonly
    _recursive_unset_readonly(v)
  File "/private/home/abaevski/.conda/envs/fairseq-fp16-20200821/lib/python3.6/site-packages/hydra/_internal/config_loader_impl.py", line 915, in _recursive_unset_readonly
    for item in cfg:
  File "/private/home/abaevski/.conda/envs/fairseq-fp16-20200821/lib/python3.6/site-packages/omegaconf/listconfig.py", line 439, in __iter__
    return self._iter_ex(resolve=True)
  File "/private/home/abaevski/.conda/envs/fairseq-fp16-20200821/lib/python3.6/site-packages/omegaconf/listconfig.py", line 468, in _iter_ex
    self._format_and_raise(key=None, value=None, cause=e)
  File "/private/home/abaevski/.conda/envs/fairseq-fp16-20200821/lib/python3.6/site-packages/omegaconf/base.py", line 101, in _format_and_raise
    type_override=type_override,
  File "/private/home/abaevski/.conda/envs/fairseq-fp16-20200821/lib/python3.6/site-packages/omegaconf/_utils.py", line 675, in format_and_raise
    _raise(ex, cause)
  File "/private/home/abaevski/.conda/envs/fairseq-fp16-20200821/lib/python3.6/site-packages/omegaconf/_utils.py", line 591, in _raise
    raise ex  # set end OC_CAUSE=1 for full backtrace
omegaconf.errors.ConfigTypeError: Cannot iterate a ListConfig object representing None
	full_key: my_field
	reference_type=Optional[List[int]]
	object_type=list

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "hydra_ex.py", line 19, in <module>
    main()
  File "/private/home/abaevski/.conda/envs/fairseq-fp16-20200821/lib/python3.6/site-packages/hydra/main.py", line 37, in decorated_main
    strict=strict,
  File "/private/home/abaevski/.conda/envs/fairseq-fp16-20200821/lib/python3.6/site-packages/hydra/_internal/utils.py", line 347, in _run_hydra
    lambda: hydra.run(
  File "/private/home/abaevski/.conda/envs/fairseq-fp16-20200821/lib/python3.6/site-packages/hydra/_internal/utils.py", line 201, in run_and_report
    raise ex
  File "/private/home/abaevski/.conda/envs/fairseq-fp16-20200821/lib/python3.6/site-packages/hydra/_internal/utils.py", line 198, in run_and_report
    return func()
  File "/private/home/abaevski/.conda/envs/fairseq-fp16-20200821/lib/python3.6/site-packages/hydra/_internal/utils.py", line 350, in <lambda>
    overrides=args.overrides,
  File "/private/home/abaevski/.conda/envs/fairseq-fp16-20200821/lib/python3.6/site-packages/hydra/_internal/hydra.py", line 104, in run
    run_mode=RunMode.RUN,
  File "/private/home/abaevski/.conda/envs/fairseq-fp16-20200821/lib/python3.6/site-packages/hydra/_internal/hydra.py", line 512, in compose_config
    from_shell=from_shell,
  File "/private/home/abaevski/.conda/envs/fairseq-fp16-20200821/lib/python3.6/site-packages/hydra/_internal/config_loader_impl.py", line 159, in load_configuration
    raise ConfigCompositionException() from e
hydra.errors.ConfigCompositionException

@omry
Copy link
Collaborator

omry commented Nov 3, 2020

There are two bugs here, one in Hydra 1.0 (not in master) and one in OmegaConf (both 2.0 and master):

OmegaConf issue.

@jieru-hu
Copy link
Contributor

jieru-hu commented Nov 6, 2020

fix is merged to both branches. closing now.

@jieru-hu jieru-hu closed this as completed Nov 6, 2020
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
3 participants