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

Unclear error: incorrect type for field of dataclass instance #435

Closed
3 tasks
adriansahlman opened this issue Nov 8, 2020 · 3 comments · Fixed by #559
Closed
3 tasks

Unclear error: incorrect type for field of dataclass instance #435

adriansahlman opened this issue Nov 8, 2020 · 3 comments · Fixed by #559
Labels
bug Something isn't working
Milestone

Comments

@adriansahlman
Copy link

Describe the bug
When using the incorrect value type for a field in a dataclass instance and then using that to construct a config object the error message is quite unclear.

To Reproduce

import omegaconf
import dataclasses
@dataclasses.dataclass
class Config:
    some_field: int = 3

omegaconf.OmegaConf.create(Config(some_field='test'))

gives the error

omegaconf.errors.ValidationError: Value 'None' could not be converted to Integer
	full_key: 
	reference_type=None
	object_type=None

Expected behavior
I would love to have the same behavior as when running

omegaconf.OmegaConf.merge(Config, {'some_field':'test'})

which gives

omegaconf.errors.ValidationError: Value 'test' could not be converted to Integer
	full_key: some_field
	reference_type=Optional[Config]
	object_type=Config

Additional context

  • OmegaConf version: 2.0.2
  • Python version: 3.8.3
  • Operating system : Ubuntu 18.04

This issue is not important, it was just something I discovered while testing out error messages for a framework.

@adriansahlman adriansahlman added the bug Something isn't working label Nov 8, 2020
@omry omry added this to the OmegaConf 2.1 milestone Nov 8, 2020
@omry
Copy link
Owner

omry commented Nov 8, 2020

Thanks for reporting, we will look into it.

@omry
Copy link
Owner

omry commented Nov 8, 2020

It may be pretty hard: I think that despite the two things looking similar, the error happens in a very different code paths.

@adriansahlman
Copy link
Author

Ah, too bad. But no worries, I have made a somewhat hacky solution in the meanwhile. Don't bother if it is too much work. If I had more time I would take a look myself and see if I could contribute somehow.

Jasha10 added a commit to Jasha10/omegaconf that referenced this issue Feb 22, 2021
Jasha10 added a commit to Jasha10/omegaconf that referenced this issue Feb 23, 2021
Jasha10 added a commit to Jasha10/omegaconf that referenced this issue Feb 23, 2021
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
2 participants