lostisland / sawyer

Secret User Agent of HTTP
MIT License
249 stars 75 forks source link

YAML marshal broken in Ruby 2.5+ (Psych 3.0+) #54

Open nomadium opened 6 years ago

nomadium commented 6 years ago

Please see below, it seems to be a breaking change with Psych from Ruby 2.4 to Ruby 2.5.

Ruby 2.4 shipped Psych 2.2.2 and those tests passed.

Ruby 2.5 shipped Psych 3.0.0 and those tests are failing.

admin@ip-172-31-24-33:~/sawyer$ bundle exec rake
/home/admin/.rubies/ruby-2.5.0/bin/ruby -w -I"lib:lib:test" -I"/home/admin/.rubies/ruby-2.5.0/lib/ruby/gems/2.5.0/gems/rake-12.3.0/lib" "/home/admin/.rubies/ruby-2.5.0/lib/ruby/gems/2.5.0/gems/rake-12.3.0/lib/rake/rake_test_loader.rb" "test/agent_test.rb" "test/relation_test.rb" "test/resource_test.rb" "test/response_test.rb" 
/home/admin/.gem/ruby/2.5.0/gems/addressable-2.5.2/lib/addressable/idna/pure.rb:154: warning: assigned but unused variable - startercc
Run options: --seed 34678

# Running:

WARNING: Unexpected middleware set after the adapter. This won't be supported from Faraday 1.0.
.........E............E.........................

Finished in 0.391983s, 122.4542 runs/s, 497.4702 assertions/s.

  1) Error:
Sawyer::AgentTest#test_handle_yaml_dump_and_load:
TypeError: allocator undefined for Method
    /home/admin/.rubies/ruby-2.5.0/lib/ruby/2.5.0/psych/visitors/to_ruby.rb:373:in `allocate'
    /home/admin/.rubies/ruby-2.5.0/lib/ruby/2.5.0/psych/visitors/to_ruby.rb:373:in `revive'
    /home/admin/.rubies/ruby-2.5.0/lib/ruby/2.5.0/psych/visitors/to_ruby.rb:208:in `visit_Psych_Nodes_Mapping'
    /home/admin/.rubies/ruby-2.5.0/lib/ruby/2.5.0/psych/visitors/visitor.rb:16:in `visit'
    /home/admin/.rubies/ruby-2.5.0/lib/ruby/2.5.0/psych/visitors/visitor.rb:6:in `accept'
    /home/admin/.rubies/ruby-2.5.0/lib/ruby/2.5.0/psych/visitors/to_ruby.rb:32:in `accept'
    /home/admin/.rubies/ruby-2.5.0/lib/ruby/2.5.0/psych/visitors/to_ruby.rb:338:in `block in revive_hash'
    /home/admin/.rubies/ruby-2.5.0/lib/ruby/2.5.0/psych/visitors/to_ruby.rb:336:in `each'
    /home/admin/.rubies/ruby-2.5.0/lib/ruby/2.5.0/psych/visitors/to_ruby.rb:336:in `each_slice'
    /home/admin/.rubies/ruby-2.5.0/lib/ruby/2.5.0/psych/visitors/to_ruby.rb:336:in `revive_hash'
    /home/admin/.rubies/ruby-2.5.0/lib/ruby/2.5.0/psych/visitors/to_ruby.rb:374:in `revive'
    /home/admin/.rubies/ruby-2.5.0/lib/ruby/2.5.0/psych/visitors/to_ruby.rb:208:in `visit_Psych_Nodes_Mapping'
    /home/admin/.rubies/ruby-2.5.0/lib/ruby/2.5.0/psych/visitors/visitor.rb:16:in `visit'
    /home/admin/.rubies/ruby-2.5.0/lib/ruby/2.5.0/psych/visitors/visitor.rb:6:in `accept'
    /home/admin/.rubies/ruby-2.5.0/lib/ruby/2.5.0/psych/visitors/to_ruby.rb:32:in `accept'
    /home/admin/.rubies/ruby-2.5.0/lib/ruby/2.5.0/psych/visitors/to_ruby.rb:338:in `block in revive_hash'
    /home/admin/.rubies/ruby-2.5.0/lib/ruby/2.5.0/psych/visitors/to_ruby.rb:336:in `each'
    /home/admin/.rubies/ruby-2.5.0/lib/ruby/2.5.0/psych/visitors/to_ruby.rb:336:in `each_slice'
    /home/admin/.rubies/ruby-2.5.0/lib/ruby/2.5.0/psych/visitors/to_ruby.rb:336:in `revive_hash'
    /home/admin/.rubies/ruby-2.5.0/lib/ruby/2.5.0/psych/visitors/to_ruby.rb:374:in `revive'
    /home/admin/.rubies/ruby-2.5.0/lib/ruby/2.5.0/psych/visitors/to_ruby.rb:208:in `visit_Psych_Nodes_Mapping'
    /home/admin/.rubies/ruby-2.5.0/lib/ruby/2.5.0/psych/visitors/visitor.rb:16:in `visit'
    /home/admin/.rubies/ruby-2.5.0/lib/ruby/2.5.0/psych/visitors/visitor.rb:6:in `accept'
    /home/admin/.rubies/ruby-2.5.0/lib/ruby/2.5.0/psych/visitors/to_ruby.rb:32:in `accept'
    /home/admin/.rubies/ruby-2.5.0/lib/ruby/2.5.0/psych/visitors/to_ruby.rb:311:in `visit_Psych_Nodes_Document'
    /home/admin/.rubies/ruby-2.5.0/lib/ruby/2.5.0/psych/visitors/visitor.rb:16:in `visit'
    /home/admin/.rubies/ruby-2.5.0/lib/ruby/2.5.0/psych/visitors/visitor.rb:6:in `accept'
    /home/admin/.rubies/ruby-2.5.0/lib/ruby/2.5.0/psych/visitors/to_ruby.rb:32:in `accept'
    /home/admin/.rubies/ruby-2.5.0/lib/ruby/2.5.0/psych/nodes/node.rb:50:in `to_ruby'
    /home/admin/.rubies/ruby-2.5.0/lib/ruby/2.5.0/psych.rb:264:in `load'
    /home/admin/sawyer/test/agent_test.rb:174:in `test_handle_yaml_dump_and_load'

  2) Error:
Sawyer::ResourceTest#test_handle_yaml_dump:
TypeError: can't dump anonymous class: #<Class:#<Sawyer::Resource:0x00005593f935e980>>
    /home/admin/.rubies/ruby-2.5.0/lib/ruby/2.5.0/psych/visitors/yaml_tree.rb:343:in `visit_Class'
    /home/admin/.rubies/ruby-2.5.0/lib/ruby/2.5.0/psych/visitors/yaml_tree.rb:136:in `accept'
    /home/admin/.rubies/ruby-2.5.0/lib/ruby/2.5.0/psych/visitors/yaml_tree.rb:546:in `block in dump_ivars'
    /home/admin/.rubies/ruby-2.5.0/lib/ruby/2.5.0/psych/visitors/yaml_tree.rb:544:in `each'
    /home/admin/.rubies/ruby-2.5.0/lib/ruby/2.5.0/psych/visitors/yaml_tree.rb:544:in `dump_ivars'
    /home/admin/.rubies/ruby-2.5.0/lib/ruby/2.5.0/psych/visitors/yaml_tree.rb:163:in `visit_Object'
    /home/admin/.rubies/ruby-2.5.0/lib/ruby/2.5.0/psych/visitors/yaml_tree.rb:136:in `accept'
    /home/admin/.rubies/ruby-2.5.0/lib/ruby/2.5.0/psych/visitors/yaml_tree.rb:118:in `push'
    /home/admin/.rubies/ruby-2.5.0/lib/ruby/2.5.0/psych.rb:441:in `dump'
    /home/admin/sawyer/test/resource_test.rb:172:in `test_handle_yaml_dump'

48 runs, 195 assertions, 0 failures, 2 errors, 0 skips
rake aborted!
Command failed with status (1): [ruby -w -I"lib:lib:test" -I"/home/admin/.rubies/ruby-2.5.0/lib/ruby/gems/2.5.0/gems/rake-12.3.0/lib" "/home/admin/.rubies/ruby-2.5.0/lib/ruby/gems/2.5.0/gems/rake-12.3.0/lib/rake/rake_test_loader.rb" "test/agent_test.rb" "test/relation_test.rb" "test/resource_test.rb" "test/response_test.rb" ]
/home/admin/.gem/ruby/2.5.0/gems/bundler-1.16.1/lib/bundler/cli/exec.rb:75:in `load'
/home/admin/.gem/ruby/2.5.0/gems/bundler-1.16.1/lib/bundler/cli/exec.rb:75:in `kernel_load'
/home/admin/.gem/ruby/2.5.0/gems/bundler-1.16.1/lib/bundler/cli/exec.rb:28:in `run'
/home/admin/.gem/ruby/2.5.0/gems/bundler-1.16.1/lib/bundler/cli.rb:424:in `exec'
/home/admin/.gem/ruby/2.5.0/gems/bundler-1.16.1/lib/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
/home/admin/.gem/ruby/2.5.0/gems/bundler-1.16.1/lib/bundler/vendor/thor/lib/thor/invocation.rb:126:in `invoke_command'
/home/admin/.gem/ruby/2.5.0/gems/bundler-1.16.1/lib/bundler/vendor/thor/lib/thor.rb:387:in `dispatch'
/home/admin/.gem/ruby/2.5.0/gems/bundler-1.16.1/lib/bundler/cli.rb:27:in `dispatch'
/home/admin/.gem/ruby/2.5.0/gems/bundler-1.16.1/lib/bundler/vendor/thor/lib/thor/base.rb:466:in `start'
/home/admin/.gem/ruby/2.5.0/gems/bundler-1.16.1/lib/bundler/cli.rb:18:in `start'
/home/admin/.gem/ruby/2.5.0/gems/bundler-1.16.1/exe/bundle:30:in `block in <top (required)>'
/home/admin/.gem/ruby/2.5.0/gems/bundler-1.16.1/lib/bundler/friendly_errors.rb:122:in `with_friendly_errors'
/home/admin/.gem/ruby/2.5.0/gems/bundler-1.16.1/exe/bundle:22:in `<top (required)>'
/home/admin/.gem/ruby/2.5.0/bin/bundle:23:in `load'
/home/admin/.gem/ruby/2.5.0/bin/bundle:23:in `<main>'
Tasks: TOP => default => test
(See full trace by running task with --trace)
admin@ip-172-31-24-33:~/sawyer$ ruby -v
ruby 2.5.0p0 (2017-12-25 revision 61468) [x86_64-linux]
admin@ip-172-31-24-33:~/sawyer$ 
technoweenie commented 5 years ago

Thanks for filing this. I'm going to attempt to skip the yaml tests on Ruby 2.5+ for now. I'll leave this issue open until someone can fix the yaml/psych issues. I've never dug into Psych, and haven't had much figuring out how encode_with(coder) should be implemented (or if it's even the fix here).