Skip to content

Uninitialized constant error for nested class of Grape::API class when using bootsnap and sidekiqswarm #2258

Closed
@guigs

Description

@guigs

The error only happens when booting a Rails app in a particular way (sidekiqswarm) when loading a nested class whose parent class inherits from Grape::API.

For example:

# app/api/thing.rb
class Thing < Grape::API; end

# app/api/thing/nested_thing.rb
class Thing
  class NestedThing; end
end

When started with sidekiqswarm, the application crash with:

/home/guigs/.rbenv/versions/3.0.3/lib/ruby/gems/3.0.0/gems/grape-1.6.2/lib/grape/api.rb:87:in `const_get': uninitialized constant #<Class:0x00007f5b1c6cb2d0>::NestedThing (NameError)
Did you mean?  MyApi::Thing::NestedThing
        from /home/guigs/.rbenv/versions/3.0.3/lib/ruby/gems/3.0.0/gems/grape-1.6.2/lib/grape/api.rb:87:in `const_missing'
        from /home/guigs/grapeboot/config/routes.rb:8:in `block in <main>'
        from /home/guigs/.rbenv/versions/3.0.3/lib/ruby/gems/3.0.0/gems/actionpack-7.0.3/lib/action_dispatch/routing/route_set.rb:428:in `instance_exec'
        from /home/guigs/.rbenv/versions/3.0.3/lib/ruby/gems/3.0.0/gems/actionpack-7.0.3/lib/action_dispatch/routing/route_set.rb:428:in `eval_block'
        from /home/guigs/.rbenv/versions/3.0.3/lib/ruby/gems/3.0.0/gems/actionpack-7.0.3/lib/action_dispatch/routing/route_set.rb:410:in `draw'
        from /home/guigs/grapeboot/config/routes.rb:1:in `<main>'
        from /home/guigs/.rbenv/versions/3.0.3/lib/ruby/gems/3.0.0/gems/bootsnap-1.11.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:39:in `load'

The problem does not happen if DISABLE_BOOTSNAP_LOAD_PATH_CACHE=1 is used.

I've created a minimum Rails app to demonstrate the problem: https://github.com/heyjobs/grapeboot

Related Sidekiq issue: sidekiq/sidekiq#5346
Related Bootsnap issue: Shopify/bootsnap#416

This has been fixed now in Bootsnap, but it was suggested that behavior should be fixed in Grape.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions