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

Frozen hashes in Ruby 3.1 #648

Closed
23tux opened this issue Jan 27, 2023 · 3 comments
Closed

Frozen hashes in Ruby 3.1 #648

23tux opened this issue Jan 27, 2023 · 3 comments

Comments

@23tux
Copy link

23tux commented Jan 27, 2023

I noticed when upgrading to Ruby 3.1, that this lines causes the loaded hashes to be frozen:

if YAML.respond_to?(:unsafe_load_file) # Psych 4.0 way
[YAML.unsafe_load_file(filename, symbolize_names: true, freeze: true), true]
else

and

if ::JSON.respond_to?(:load_file)
[::JSON.load_file(filename, symbolize_names: true, freeze: true), true]
else

We do some manipulations to the loaded translations like parsing markdown and writing the results back to the translation hashes. This now throws a can't modify frozen Hash error when trying to set a key on that hash.

I wonder why this is? Can someone elaborate why the files are loaded with freeze: true? Is this for performance reasons?

And what would a good way of customize this? For now I can only think of monkey patching the load_yml and load_json method, even if it's very ugly and complicates future gem updates.

Or is there some hook or custom backend or anything like this, that would be better than monkey patching the method?

@radar
Copy link
Collaborator

radar commented Feb 3, 2023

Here's the pull request #587

@msxavi
Copy link

msxavi commented May 18, 2023

#587 didn’t fix YML, did it?

@radar
Copy link
Collaborator

radar commented May 18, 2023

That one was just for JSON. Are you seeing issues with YML too? If so, please open a different issue.

@ruby-i18n ruby-i18n locked as resolved and limited conversation to collaborators May 18, 2023
@radar radar closed this as completed Jun 21, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants