ruby / json

JSON implementation for Ruby
https://ruby.github.io/json
Other
673 stars 326 forks source link

Making OpenStruct as optional break things #579

Closed kujma10 closed 6 months ago

kujma10 commented 6 months ago

Hello,

we have been using graphql gem in our project (quite an old version - 1.11.10). New version of Json (2.7.2) (updated automatically by range ~->) caused namespace conflicts with graphql gem resulting an error uninitialized constant GraphQL::Compatibility::ExecutionSpecification::SpecificationSchema::OpenStruct on this line. As a temporary fix we had to lock the version back to 2.7.1. The breaking change: https://github.com/flori/json/pull/565

As a long term fix we will be looking to update graphql but posting it here in case this update causes issues for others too. Also, maybe worth to look into that change from "Json" perspective too.

Thanks

ebendev commented 6 months ago

We had the same issue and what it amounts to is that code in our project was making use of OpenStruct from Ruby without explicitly doing any require 'ostruct'. It's actually the change in https://github.com/flori/json/pull/577 that revealed this flaw, as that's what causes JSON::GenericObject to not be loaded when the json gem is required/loaded, which means the require 'ostruct' line in lib/json/generic_object.rb (which is still there, btw) is not executed until that file is explicitly loaded.

Anyone seeing this after upgrading to json 2.7.2 merely needs to add require 'ostruct' in their project wherever they are using OpenStruct.

hsbt commented 6 months ago

Thanks for your report.

Unfortunately, It's not json issue. Every gem should require dependent libraries themselves.

Anyone seeing this after upgrading to json 2.7.2 merely needs to add require 'ostruct' in their project wherever they are using OpenStruct.

Correct. I'm not sure what usage that in your application. You can simply fix this to add require "ostruct" in your config/application.rb if you use Rails.

kujma10 commented 6 months ago

Thanks @ebendev and @hsbt. The issue got resolved by adding require "ostruct". Ideally it should be graphql gem requiring that (most likely it does in newer versions) but definetely this is better workaround for us than locking down the json gem