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

Vague error for equals sign in resolver when creating config from dataclass #697

Closed
addisonklinke opened this issue Apr 28, 2021 · 3 comments · Fixed by #701
Closed

Vague error for equals sign in resolver when creating config from dataclass #697

addisonklinke opened this issue Apr 28, 2021 · 3 comments · Fixed by #701
Labels
bug Something isn't working
Milestone

Comments

@addisonklinke
Copy link

Describe the bug
If users create their config from dataclass objects (Hydra structured configs) and accidentally put an equals sign in a resolver string, the error traceback is vague and does not point to the offending key

To Reproduce

from dataclasses import dataclass
import traceback
from omegaconf import DictConfig, OmegaConf
from omegaconf.errors import GrammarParseError


# The root cause is the equals sign in ``default=``
problematic_equals_resolver = '${oc.env:API_KEY, default=abc123}'

# Dataclass configs (produce vague error)
@dataclass
class ConnectConf:
    api_key: str = problematic_equals_resolver

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

@dataclass
class Conf:
    tasks: TasksConf = TasksConf()

# Plain dict config (produces good error)
dict_conf = {
    'tasks': {
        'connect': {
            'api_key': problematic_equals_resolver}}}

# Checkout the stack traces
try:
    OmegaConf.create(dict_conf)
except GrammarParseError:
    traceback.print_exc()
    print('^^ Good error showing a ``full_key`` value\n\n')
try:
    OmegaConf.create(Conf)
except GrammarParseError:
    traceback.print_exc()
    print('^^ Vague error with an empty ``full_key``\n\n')

Expected behavior
Whether the OmegaConf config is created from a plain dict or dataclasses, the error should have full_key: tasks.connect.api_key

Additional context

  • OmegaConf version: 2.1.0.dev24
  • Python version: 3.6.13
  • Operating system: Ubuntu 18.04
@addisonklinke addisonklinke added the bug Something isn't working label Apr 28, 2021
@omry
Copy link
Owner

omry commented Apr 28, 2021

Creation errors in dataclasses are not optimal right now. This is something we will try to improve in OmegaConf 2.2.
The issue is not specific to custom resolvers.
We will take a look to see if we can improve it in 2.1 but chances are this this and other similar issues will not be addressed in 2.1.

This is pretty close to #658.

@omry omry added this to the OmegaConf 2.1 milestone Apr 28, 2021
@addisonklinke
Copy link
Author

Ah guess this was already on your radar, but maybe this helps writing additional test cases once there's time to address it in 2.2
If not, it's fine to close if the other issue is sufficient

@omry
Copy link
Owner

omry commented Apr 28, 2021

We will take a look to see if the usage of custom resolvers here is causing any additional complications.
If not, we can just close it in favor of #658.

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