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

improve error message when creating a DictConfig from a bad dataclass #701

Merged
merged 3 commits into from
Apr 30, 2021

Conversation

omry
Copy link
Owner

@omry omry commented Apr 29, 2021

Closes #697
Closes #658

This is not really fixing it completely, but the error message is more helpful.
It does indicate the offending type. and the key inside it instead of the full key in the config object. (providing the full key will be handled as a part of #514.

@omry omry requested review from Jasha10 and jieru-hu April 29, 2021 21:11
@jieru-hu
Copy link
Collaborator

Could you paste what the new error message looks like?

@omry
Copy link
Owner Author

omry commented Apr 30, 2021

from dataclasses import dataclass

from omegaconf import OmegaConf


@dataclass
class ConnectConf:
    # The root cause is the equals sign in ``default=``
    api_key: str = "${oc.env:API_KEY, default=abc123}"


@dataclass
class TasksConf:
    connect: ConnectConf = ConnectConf()


OmegaConf.structured(TasksConf)

Output:

Traceback (most recent call last):
....
omegaconf.errors.GrammarParseError: token recognition error at: '='
    full_key: api_key
    object_type=ConnectConf

Copy link
Collaborator

@jieru-hu jieru-hu left a comment

Choose a reason for hiding this comment

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

lgtm

@Jasha10
Copy link
Collaborator

Jasha10 commented Apr 30, 2021

Looks like a good improvement.
This does close #697, but I think that #658 is not resolved yet:

$ cat tmp658.py
from typing import Tuple
from dataclasses import dataclass
from omegaconf import OmegaConf

@dataclass
class TopLvlConf:
    foo: Tuple[str] = 123

OmegaConf.create(TopLvlConf)
$ python tmp658.py
Traceback (most recent call last):
...
omegaconf.errors.ValidationError: Invalid value assigned: int is not a ListConfig, list or tuple.
    full_key:
    object_type=None

@Jasha10
Copy link
Collaborator

Jasha10 commented Apr 30, 2021

I am working on a diff that will close #658.

@Jasha10
Copy link
Collaborator

Jasha10 commented Apr 30, 2021

I've pushed a commit to patch #658.

$ python tmp658.py
Traceback (most recent call last):
...
omegaconf.errors.ValidationError: Invalid value assigned: int is not a ListConfig, list or tuple.
    full_key: foo
    object_type=None

@Jasha10 Jasha10 requested a review from jieru-hu April 30, 2021 16:38
@omry
Copy link
Owner Author

omry commented Apr 30, 2021

Good catch Jasha, and thanks for the patch.

@omry omry merged commit 3b04bf9 into master Apr 30, 2021
@omry omry deleted the 697 branch April 30, 2021 17:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants