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

Disable automatic conversion of date strings in from_dotlist #95

Closed
shuki-hpcnt opened this issue Dec 10, 2019 · 1 comment · Fixed by #96
Closed

Disable automatic conversion of date strings in from_dotlist #95

shuki-hpcnt opened this issue Dec 10, 2019 · 1 comment · Fixed by #96

Comments

@shuki-hpcnt
Copy link
Contributor

Issue

When instantiating OmegaConf from from_dotlist, yaml loader tries to convert date-formatted strings into date type, therefore raises error when validating the type of values.

 OmegaConf.from_dotlist(["my_date=2019-11-11"])

>>>

.../site-packages/omegaconf/config.py in _prepare_value_to_add(self, key, value)
    448         if not Config.is_primitive_type(value):
    449             full_key = self.get_full_key(key)
--> 450             raise ValueError("key {}: {} is not a primitive type".format(full_key, type(value).__name__))
    451
    452         if self._get_flag('readonly'):

ValueError: key my_date: date is not a primitive type

This error also blocks the overriding of configuration values by using cli arguments in hydra.

Potential workaround

Could be solved by removing implicit timestamp resolvers in default yaml.SafeLoader.
(Related stackoverflow: https://stackoverflow.com/questions/34667108/ignore-dates-and-times-while-parsing-yaml)

@omry
Copy link
Owner

omry commented Dec 10, 2019

Thanks for reporting.
For now try to indicate that those are strings:

In [4]: OmegaConf.from_dotlist(["my_date=!!str 2019-11-11"])
Out[4]: {'my_date': '2019-11-11'}

This should work from command line if you wrap the key=value pair: "my_date=!!str 2019-11-11"
although I did not test yet.

I would appreciate a PR that disables it.
I am on vacation so it may be a while before I am able to fix it.

There is already some adjustments to the build in resolvers here:

https://github.com/omry/omegaconf/blob/master/omegaconf/config.py#L26-L42

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants