palkan/anyway_config

Error loading date values from yaml files with ruby 3.3.0

Closed this issue · 3 comments

What did you do?

Updated an existing rails project to ruby 3.3.0

What did you expect to happen?

No changes in behaviour from our previous ruby 3.0.1 implementation.

What actually happened?

On initialising an instance of a *Config class, it fails with this error:

Tried to load unspecified class: Date (Psych::DisallowedClass)

Additional context

This appears to be a deliberate decision with Psych, where some types are disallowed unless they are explicitly allowed.

This is actually the most minimal reproduction of this issue I've found (without using Anywayconfig):

YAML.load("1988-03-08")

It can then be corrected by adding permitted_classes:

YAML.load("1988-03-08", permitted_classes: [Date])

This is also true of YAML.load_file.

Armed with this information I've found two ways to address the issue:

  • Modifying Anyway::Loaders::YAML to pass Date in to the permitted_classes key
  • Changing my yaml files to force these values to be strings, then coercing them back to dates.

I have created a github repo with a minimal reproduction of this issue on ruby 3.3.0 and Anyway 2.6.2. There you can find information in README.md and the three files in examples/

Environment

**Ruby Version: 3.3.0

Anyway Config Version: 2.6.2


As you can see, I have a workaround which I can use for now, but I'd be surprised if other people aren't running into this issue. If you choose not to modify the gem, it would be good to document it so this workaround can be found.

Changing my yaml files to force these values to be strings, then coercing them back to dates.

I think, that's the best way to do that. You can use coerce_types to automatically do the conversion.

Another possible solution could be adding the loader configuration. Smth like:

Anyway::Loaders::YAML.permitted_classes << Date

I'm currently using the workaround with forcing string types.

I like your suggested interface of adding the attribute to the YAML loader.

Released in 2.6.3