Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

YAML deserialization error on ruby 1.8.7 since version 3.29.0 #443

Closed
JonathanTron opened this Issue Feb 15, 2012 · 2 comments

Comments

Projects
None yet
2 participants
Contributor

JonathanTron commented Feb 15, 2012

Hi,
I just hit a problem when implementing a DelayedJob backend using Sequel.
It appears only on ruby 1.8.7 (checked with p357) starting with Sequel version 3.29.0, here's an example which works with Sequel 3.28.0 but fails with 3.29.0:

require "sequel"
DB = Sequel.sqlite

DB.create_table :stories do
  primary_key :id
end

class Story < Sequel::Model
  yaml_as "tag:ruby.yaml.org,2002:Sequel"

  def to_yaml_properties
   ['@values']
  end
end

s = Story.create
puts YAML.load s.to_yaml

I looked at the changes between those releases, but you're too prolific (200+ commits in 1 month).

Owner

jeremyevans commented Feb 15, 2012

In 3.29.0, Sequel::Model.call was added. Apparently in syck (the ruby 1.8 YAML parser), if the target class responds to call, it calls call with 2 arguments (the tag and the yaml properties). I consider this a design flaw in syck, which you can work around by adding the following code to your app:

class Story < Sequel::Model
  def self.call(hash, val=(one_arg=true))
    if one_arg
      super(hash)
    else
      load(val["values"])
    end
  end
end

You could also upgrade to ruby 1.9.3, which uses psych instead of syck as the YAML parser, and doesn't have this design flaw.

Contributor

JonathanTron commented Feb 15, 2012

Thanks Jeremy, the idea being to be compatible with both 1.8.7 and 1.9.x I think I will have to use this workaround.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment