-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Uninitialized constant error for nested class of Grape::API class when using bootsnap and sidekiqswarm #2258
Comments
To clarify, this is the constant I have a problem with: Line 11 in a6cde5d
If any code loaded after |
@casperisfine Makes sense. Try adding an integration test in Grape and fix this? |
I may do it at some point, but it's super low priority for me as I'm not a grape user. |
I came across this while looking into a Zeitwerk thing, but given the available information this seems like implementation error to me. Here: https://github.com/heyjobs/grapeboot/tree/main/app/api You are defining: # app/api/thing.rb
class Thing < Grape::API
end and # app/api/thing/nested_thing.rb
class Thing
class NestedThing
end
end Given that the inheritance from Grape::API is commented out I imagine you were trying it with that value present at some point, but without it that inner class is not inheriting from Grape::API. For example: class Thing < Grape::API
end
class Thing
class NestedThing
end
end
# subclass <= superclass will evaluate to true:
Thing <= Grape::API
=> true
Thing::NestedThing <= Grape::API
=> nil
Thing::NestedThing <= Thing
=> nil
Thing::NestedThing <= Object
=> true Apart from Thing::NestedThing not being defined as a subclass of Grape::API, the non-commented out content of your Rails.application.routes.draw do
Thing::NestedThing
end The Grape docu will tell you to either use Your original comment mentions MyApi which isn't in your test project, and in the history it looks like you had a folder named MyApi but never actually defined it as a module? I have to wonder if this wasn't a combination of not defining the module/class/inheritance/routing correctly (as demonstrated above) and improper directory structure given the files that were defined (which is a common trigger for this issue, e.g., https://stackoverflow.com/a/29307359 and needing to have the structure |
Thanks for the detailed call outs @allisonphillips! @guigs care to check it out? |
@allisonphillips Thank you for investigating. You're right in your analysis. I deliberate removed the inheritance from These were actually from of my attempts to debug this issue and a way to rule out they were not the cause. But now I see how this can make it more confusing, as it is not doing the proper thing. I just added back the inheritance and the mounting and the problem can still be reproduced. |
Fix: ruby-grape#2258 Some gems or app code may define methods on `Class` after `grape` is loaaded but before `override_all_methods!` is called. As such it's better to check `Class.method_defined?` when doing the override.
Fix: ruby-grape#2258 Some gems or app code may define methods on `Class` after `grape` is loaaded but before `override_all_methods!` is called. As such it's better to check `Class.method_defined?` when doing the override.
Sorry, totally forgot about this one. Proposed fix: #2328 |
Fix: ruby-grape#2258 Some gems or app code may define methods on `Class` after `grape` is loaaded but before `override_all_methods!` is called. As such it's better to check `Class.method_defined?` when doing the override.
Fix: ruby-grape#2258 Some gems or app code may define methods on `Class` after `grape` is loaaded but before `override_all_methods!` is called. As such it's better to check `Class.method_defined?` when doing the override.
Fix: ruby-grape#2258 Some gems or app code may define methods on `Class` after `grape` is loaaded but before `override_all_methods!` is called. As such it's better to check `Class.method_defined?` when doing the override.
Fix: ruby-grape#2258 Some gems or app code may define methods on `Class` after `grape` is loaaded but before `override_all_methods!` is called. As such it's better to check `Class.method_defined?` when doing the override.
Fix: ruby-grape#2258 Some gems or app code may define methods on `Class` after `grape` is loaaded but before `override_all_methods!` is called. As such it's better to check `Class.method_defined?` when doing the override.
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:
When started with
sidekiqswarm
, the application crash with: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.
The text was updated successfully, but these errors were encountered: