Project

General

Profile

Actions

Bug #12140

closed

Serialization of OpenStruct objects with YAML fails

Added by jmanrubia (Jorge Manrubia) almost 9 years ago. Updated over 8 years ago.

Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
ruby 2.3.0p0 (2015-12-25 revision 53290) [x86_64-darwin15]
[ruby-core:74111]

Description

When deserializing a serialized YAML open-struct object, it fails with an exception NoMethodError: undefined method key?' for nil:NilClass`.

This breaks serialized attributes in Rails 3.2 with Ruby 2.3.

To reproduce:

require 'ostruct'
require 'yaml'
YAML.load(YAML.dump(OpenStruct.new))

Full exception trace:

NoMethodError: undefined method `key?' for nil:NilClass
	from /Users/jorge/.rbenv/versions/2.3.0/lib/ruby/2.3.0/ostruct.rb:176:in `respond_to_missing?'
	from /Users/jorge/.rbenv/versions/2.3.0/lib/ruby/2.3.0/psych/visitors/to_ruby.rb:381:in `respond_to?'
	from /Users/jorge/.rbenv/versions/2.3.0/lib/ruby/2.3.0/psych/visitors/to_ruby.rb:381:in `init_with'
	from /Users/jorge/.rbenv/versions/2.3.0/lib/ruby/2.3.0/psych/visitors/to_ruby.rb:374:in `revive'
	from /Users/jorge/.rbenv/versions/2.3.0/lib/ruby/2.3.0/psych/visitors/to_ruby.rb:208:in `visit_Psych_Nodes_Mapping'
	from /Users/jorge/.rbenv/versions/2.3.0/lib/ruby/2.3.0/psych/visitors/visitor.rb:16:in `visit'
	from /Users/jorge/.rbenv/versions/2.3.0/lib/ruby/2.3.0/psych/visitors/visitor.rb:6:in `accept'
	from /Users/jorge/.rbenv/versions/2.3.0/lib/ruby/2.3.0/psych/visitors/to_ruby.rb:32:in `accept'
	from /Users/jorge/.rbenv/versions/2.3.0/lib/ruby/2.3.0/psych/visitors/to_ruby.rb:311:in `visit_Psych_Nodes_Document'
	from /Users/jorge/.rbenv/versions/2.3.0/lib/ruby/2.3.0/psych/visitors/visitor.rb:16:in `visit'
	from /Users/jorge/.rbenv/versions/2.3.0/lib/ruby/2.3.0/psych/visitors/visitor.rb:6:in `accept'
	from /Users/jorge/.rbenv/versions/2.3.0/lib/ruby/2.3.0/psych/visitors/to_ruby.rb:32:in `accept'
	from /Users/jorge/.rbenv/versions/2.3.0/lib/ruby/2.3.0/psych/nodes/node.rb:38:in `to_ruby'
	from /Users/jorge/.rbenv/versions/2.3.0/lib/ruby/2.3.0/psych.rb:253:in `load'
	from (irb):1
	from /Users/jorge/.rbenv/versions/2.3.0/bin/irb:11:in `<main>'

Related issues 1 (0 open1 closed)

Is duplicate of Ruby master - Bug #11884: Psych.load broken for OpenStruct in Ruby 2.3.0Closedmarcandre (Marc-Andre Lafortune)Actions

Updated by marcandre (Marc-Andre Lafortune) almost 9 years ago

  • Status changed from Open to Closed

Indeed, it's a dupe of #11884.

Actions #3

Updated by marcandre (Marc-Andre Lafortune) almost 9 years ago

  • Is duplicate of Bug #11884: Psych.load broken for OpenStruct in Ruby 2.3.0 added

Updated by usa (Usaku NAKAMURA) almost 9 years ago

  • Backport changed from 2.1: UNKNOWN, 2.2: UNKNOWN, 2.3: UNKNOWN to 2.1: DONTNEED, 2.2: DONTNEED, 2.3: REQUIRED

Updated by naruse (Yui NARUSE) over 8 years ago

  • Backport changed from 2.1: DONTNEED, 2.2: DONTNEED, 2.3: REQUIRED to 2.1: DONTNEED, 2.2: DONTNEED, 2.3: DONE
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0