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

Fix a build error when using Psych 4.0 #569

Merged
merged 1 commit into from Nov 2, 2021

Conversation

koic
Copy link
Contributor

@koic koic commented May 28, 2021

This PR fixes the following build error when using Psych 4.0.

% ruby -v
ruby 3.1.0dev (2021-05-17T10:51:51Z master ee611341c9) [x86_64-darwin19]

% cd path/to/i18n

% bundle exec rake
(snip)

Finished in 1.310478s, 1265.1872 runs/s, 2004.6121 assertions/s.

  1) Error:
KeyValueCacheFileTest#test_load_translations_caches_file_through_updated_modification_time:
I18n::InvalidLocaleData: can not load translations from
/var/folders/6j/5l8q3y250b97529_tcssrwlm0000gn/T/test20210528-81604-ijnu7v.yml:
#<Psych::DisallowedClass: Tried to load unspecified class: Symbol>
    /Users/koic/src/github.com/ruby-i18n/i18n/lib/i18n/backend/base.rb:245:in
    `rescue in load_yml'
    /Users/koic/src/github.com/ruby-i18n/i18n/lib/i18n/backend/base.rb:241:in
    `load_yml'
    /Users/koic/src/github.com/ruby-i18n/i18n/lib/i18n/backend/base.rb:226:in
    `load_file'
    /Users/koic/src/github.com/ruby-i18n/i18n/lib/i18n/backend/cache_file.rb:23:in
    `load_file'
    /Users/koic/src/github.com/ruby-i18n/i18n/lib/i18n/backend/base.rb:18:in
    `block in load_translations'
    /Users/koic/src/github.com/ruby-i18n/i18n/lib/i18n/backend/base.rb:18:in
    `each'
    /Users/koic/src/github.com/ruby-i18n/i18n/lib/i18n/backend/base.rb:18:in
    `load_translations'
    /Users/koic/src/github.com/ruby-i18n/i18n/test/backend/cache_file_test.rb:49:in
    `block (2 levels) in <module:CacheFileTest>'
    /Users/koic/.rbenv/versions/3.1.0-dev/lib/ruby/3.1.0/tempfile.rb:317:in
    `open'
    /Users/koic/src/github.com/ruby-i18n/i18n/test/backend/cache_file_test.rb:43:in
    `block in <module:CacheFileTest>'

  2) Error:
SimpleCacheFileTest#test_load_translations_caches_file_through_updated_modification_time:
I18n::InvalidLocaleData: can not load translations from
/var/folders/6j/5l8q3y250b97529_tcssrwlm0000gn/T/test20210528-81604-9kcvkm.yml:
#<Psych::DisallowedClass: Tried to load unspecified class: Symbol>
    /Users/koic/src/github.com/ruby-i18n/i18n/lib/i18n/backend/base.rb:245:in
    `rescue in load_yml'
    /Users/koic/src/github.com/ruby-i18n/i18n/lib/i18n/backend/base.rb:241:in
    `load_yml'
    /Users/koic/src/github.com/ruby-i18n/i18n/lib/i18n/backend/base.rb:226:in
    `load_file'
    /Users/koic/src/github.com/ruby-i18n/i18n/lib/i18n/backend/cache_file.rb:23:in
    `load_file'
    /Users/koic/src/github.com/ruby-i18n/i18n/lib/i18n/backend/base.rb:18:in
    `block in load_translations'
    /Users/koic/src/github.com/ruby-i18n/i18n/lib/i18n/backend/base.rb:18:in
    `each'
    /Users/koic/src/github.com/ruby-i18n/i18n/lib/i18n/backend/base.rb:18:in
    `load_translations'
    /Users/koic/src/github.com/ruby-i18n/i18n/lib/i18n/backend/simple.rb:79:in
    `init_translations'
    /Users/koic/src/github.com/ruby-i18n/i18n/lib/i18n/backend/simple.rb:89:in
    `lookup'
    /Users/koic/src/github.com/ruby-i18n/i18n/lib/i18n/backend/base.rb:32:in
    `translate'
    /Users/koic/src/github.com/ruby-i18n/i18n/lib/i18n.rb:207:in `block
    in translate'
    /Users/koic/src/github.com/ruby-i18n/i18n/lib/i18n.rb:203:in `catch'
    /Users/koic/src/github.com/ruby-i18n/i18n/lib/i18n.rb:203:in
    `translate'
    /Users/koic/src/github.com/ruby-i18n/i18n/test/backend/cache_file_test.rb:50:in
    `block (2 levels) in <module:CacheFileTest>'
    /Users/koic/.rbenv/versions/3.1.0-dev/lib/ruby/3.1.0/tempfile.rb:317:in
    `open'
    /Users/koic/src/github.com/ruby-i18n/i18n/test/backend/cache_file_test.rb:43:in
    `block in <module:CacheFileTest>'

1658 runs, 2627 assertions, 0 failures, 2 errors, 0 skips
rake aborted!

This breaking is because an incompatibility with Psych 4.0.

For example, this PR solves the problem of faker gem that depend on i18n gem.
faker-ruby/faker#2330

This PR fixes the following build error when using Psych 4.0.

```console
% ruby -v
ruby 3.1.0dev (2021-05-17T10:51:51Z master ee611341c9) [x86_64-darwin19]

% cd path/to/i18n

% bundle exec rake
(snip)

Finished in 1.310478s, 1265.1872 runs/s, 2004.6121 assertions/s.

  1) Error:
KeyValueCacheFileTest#test_load_translations_caches_file_through_updated_modification_time:
I18n::InvalidLocaleData: can not load translations from
/var/folders/6j/5l8q3y250b97529_tcssrwlm0000gn/T/test20210528-81604-ijnu7v.yml:
#<Psych::DisallowedClass: Tried to load unspecified class: Symbol>
    /Users/koic/src/github.com/ruby-i18n/i18n/lib/i18n/backend/base.rb:245:in
    `rescue in load_yml'
    /Users/koic/src/github.com/ruby-i18n/i18n/lib/i18n/backend/base.rb:241:in
    `load_yml'
    /Users/koic/src/github.com/ruby-i18n/i18n/lib/i18n/backend/base.rb:226:in
    `load_file'
    /Users/koic/src/github.com/ruby-i18n/i18n/lib/i18n/backend/cache_file.rb:23:in
    `load_file'
    /Users/koic/src/github.com/ruby-i18n/i18n/lib/i18n/backend/base.rb:18:in
    `block in load_translations'
    /Users/koic/src/github.com/ruby-i18n/i18n/lib/i18n/backend/base.rb:18:in
    `each'
    /Users/koic/src/github.com/ruby-i18n/i18n/lib/i18n/backend/base.rb:18:in
    `load_translations'
    /Users/koic/src/github.com/ruby-i18n/i18n/test/backend/cache_file_test.rb:49:in
    `block (2 levels) in <module:CacheFileTest>'
    /Users/koic/.rbenv/versions/3.1.0-dev/lib/ruby/3.1.0/tempfile.rb:317:in
    `open'
    /Users/koic/src/github.com/ruby-i18n/i18n/test/backend/cache_file_test.rb:43:in
    `block in <module:CacheFileTest>'

  2) Error:
SimpleCacheFileTest#test_load_translations_caches_file_through_updated_modification_time:
I18n::InvalidLocaleData: can not load translations from
/var/folders/6j/5l8q3y250b97529_tcssrwlm0000gn/T/test20210528-81604-9kcvkm.yml:
#<Psych::DisallowedClass: Tried to load unspecified class: Symbol>
    /Users/koic/src/github.com/ruby-i18n/i18n/lib/i18n/backend/base.rb:245:in
    `rescue in load_yml'
    /Users/koic/src/github.com/ruby-i18n/i18n/lib/i18n/backend/base.rb:241:in
    `load_yml'
    /Users/koic/src/github.com/ruby-i18n/i18n/lib/i18n/backend/base.rb:226:in
    `load_file'
    /Users/koic/src/github.com/ruby-i18n/i18n/lib/i18n/backend/cache_file.rb:23:in
    `load_file'
    /Users/koic/src/github.com/ruby-i18n/i18n/lib/i18n/backend/base.rb:18:in
    `block in load_translations'
    /Users/koic/src/github.com/ruby-i18n/i18n/lib/i18n/backend/base.rb:18:in
    `each'
    /Users/koic/src/github.com/ruby-i18n/i18n/lib/i18n/backend/base.rb:18:in
    `load_translations'
    /Users/koic/src/github.com/ruby-i18n/i18n/lib/i18n/backend/simple.rb:79:in
    `init_translations'
    /Users/koic/src/github.com/ruby-i18n/i18n/lib/i18n/backend/simple.rb:89:in
    `lookup'
    /Users/koic/src/github.com/ruby-i18n/i18n/lib/i18n/backend/base.rb:32:in
    `translate'
    /Users/koic/src/github.com/ruby-i18n/i18n/lib/i18n.rb:207:in `block
    in translate'
    /Users/koic/src/github.com/ruby-i18n/i18n/lib/i18n.rb:203:in `catch'
    /Users/koic/src/github.com/ruby-i18n/i18n/lib/i18n.rb:203:in
    `translate'
    /Users/koic/src/github.com/ruby-i18n/i18n/test/backend/cache_file_test.rb:50:in
    `block (2 levels) in <module:CacheFileTest>'
    /Users/koic/.rbenv/versions/3.1.0-dev/lib/ruby/3.1.0/tempfile.rb:317:in
    `open'
    /Users/koic/src/github.com/ruby-i18n/i18n/test/backend/cache_file_test.rb:43:in
    `block in <module:CacheFileTest>'

1658 runs, 2627 assertions, 0 failures, 2 errors, 0 skips
rake aborted!
```

This breaking is because an incompatibility with Psych 4.0.

- ruby/psych#487
- https://bugs.ruby-lang.org/issues/17866

For example, this PR solves the problem of faker gem that depend on i18n gem.
faker-ruby/faker#2330
@msjanjua
Copy link

Hi,
I am not sure if I missed something but this is what I did based on the above:

C:\Ruby27-x64\lib\ruby\gems\2.7.0\gems\i18n-1.8.10\lib\i18n

ran "bundle exec rake"
and got "Could not locate Gemfile or .bundle/ directory"

Do you know what's wrong here?

Thanks

@jhawthorn
Copy link
Contributor

jhawthorn commented Oct 25, 2021

👍 This works to solve the faker (or any other translations with aliases) issue for us

@SamSaffron
Copy link

@radar wondering if there is any chance this could be merged? Ruby 3.1 with yjit goodness is just around the corner and it ships with latest Psych which makes for a bit of an adventure getting old projects working

(also just for visibility @tenderlove )

@radar
Copy link
Collaborator

radar commented Nov 2, 2021

LGTM, thank you @koic :)

@radar radar merged commit 916f9f4 into ruby-i18n:master Nov 2, 2021
@koic koic deleted the fix_build_error_when_using_psych_4_0 branch November 2, 2021 23:55
Copy link

@Sarkar44 Sarkar44 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

change

Copy link

@Sarkar44 Sarkar44 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

approve

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 this pull request may close these issues.

None yet

6 participants