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

json_pure >= 2 incompatible with (Rails) ActiveSupport 4.2 #34

Closed
fcarreiro opened this Issue Jul 2, 2016 · 2 comments

Comments

Projects
None yet
2 participants
@fcarreiro

fcarreiro commented Jul 2, 2016

Hello, the story goes as follows:
I was using Ruby 2.3.0 and the gems

gem 'rails', '~> 4.2.6'
gem 'paperclip', '~> 4.3.6'
gem 'aws-sdk', '< 2.0.0'

and both Rails and everything related to AWS and JSON worked ok.
After a bundle update, with the following gemset

gem 'rails', '~> 4.2.6'
gem 'paperclip', '~> 5.0.0'
gem 'aws-sdk', '>= 2.0.34'

I ended up with the gems

    aws-sdk-core (2.3.19)
      jmespath (~> 1.0)
    jmespath (1.2.4)
      json_pure (>= 1.8.1)
    json_pure (2.0.1)

Suddenly I was getting a JSON::ParserError when ActiveRecord tried to deserialize a JSON store in one of my models, for reference:

class Reaction < ActiveRecord::Base
  store :content, accessors: [:like, :dislike, :vote], coder: JSON
  [...]
end

The stack trace (starting from ActiveRecord) is

json_pure (2.0.1) lib/json/common.rb:156:in `parse'
json_pure (2.0.1) lib/json/common.rb:156:in `parse'
json_pure (2.0.1) lib/json/common.rb:337:in `load'
activerecord (4.2.6) lib/active_record/store.rb:190:in `load'
activerecord (4.2.6) lib/active_record/type/serialized.rb:58:in `default_value?'
activerecord (4.2.6) lib/active_record/type/serialized.rb:16:in `type_cast_from_database'
activerecord (4.2.6) lib/active_record/attribute.rb:104:in `type_cast'
activerecord (4.2.6) lib/active_record/attribute.rb:42:in `original_value'
activerecord (4.2.6) lib/active_record/attribute.rb:37:in `value'
activerecord (4.2.6) lib/active_record/attribute_set.rb:31:in `fetch_value'
activerecord (4.2.6) lib/active_record/attribute_methods/read.rb:93:in `_read_attribute'
activerecord (4.2.6) lib/active_record/attribute_methods.rb:50:in `__temp__36f6e64756e647'
activerecord (4.2.6) lib/active_record/store.rb:166:in `prepare'
activerecord (4.2.6) lib/active_record/store.rb:137:in `read'
activerecord (4.2.6) lib/active_record/store.rb:122:in `read_store_attribute'
activerecord (4.2.6) lib/active_record/store.rb:90:in `block (3 levels) in store_accessor'

After some looking around, it looks like JSON parsers ('json', 'json_pure') before version 2 would load nil and '' as nil (equivalently, they would parse 'null' as nil). However, the behaviour apparently changed in version 2. This is probably the reason for the following requirement that Rails sets on the gems

    activesupport (4.2.6)
      i18n (~> 0.7)
      json (~> 1.7, >= 1.7.7)

There you can see that version 1 of json is required. Therefore, as jmespath requires json_pure, which is naturally set to the highest version, then it breaks Rails (since it is overriding the JSON module).

For the moment, I fixed this by setting

gem 'json_pure', '~> 1.7'

in my gemfile, but I don't know if jmespath really relies on features from json_pure v2 (I guess it shouldn't, given the gemspec accepts v1). In any case, it would be interesting (for me) to understand why you use json_pure instead of json. I thought (but I'm not sure) that the 'json' module tries to load the C extension and falls back to pure if it fails.

Regards,
Facundo

@trevorrowe

This comment has been minimized.

Contributor

trevorrowe commented Jul 6, 2016

The dependency is intentionally on json_pure instead of json. Environments that do not have the ability to install gems with native dependencies fail during install. I'm currently trying to see what can be done to remove the dependency.

@trevorrowe

This comment has been minimized.

Contributor

trevorrowe commented Jul 6, 2016

Closed by #35. We've removed the dependency on json_pure, and have added some additional code to deal with the old Ruby 1.9.3 & JSON 1.5.5 differences.

@trevorrowe trevorrowe closed this Jul 6, 2016

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