-
-
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
After 1.5.0 , 'route_setting :custom , key: :value' is broken with 'mount'. #2173
Comments
Probably a bug. Turn it into a failing spec and PR that? |
I write spec and pr on #2174 . |
I find problem point and solve with rollback that line. #2174
I give up performance during init. |
I was about to open an issue about it, I even created a file to test it. require "bundler/inline"
gemfile(true) do
source "https://rubygems.org"
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
gem "grape", "1.5.3"
end
require "grape"
class BaseAPI < Grape::API
end
class SomeAPI < Grape::API
route_setting :auth, public: true
get '/a' do
end
route_setting :auth, public: true
get '/b' do
end
end
raise 'ERROR ON /a' if SomeAPI.routes.first.settings[:auth] != { public: true }
raise 'ERROR ON /b' if SomeAPI.routes.last.settings[:auth] != { public: true }
BaseAPI.mount SomeAPI
raise 'ERROR ON /a after mount' if SomeAPI.routes.first.settings[:auth] != { public: true }
raise 'ERROR ON /b after mount' if SomeAPI.routes.last.settings[:auth] != { public: true } |
I was about to open an issue about this as well... I looked around the Grape code and I'm not sure how to actually fix the issue. However, I noticed that adding an empty Slightly modified reproduction of @stephannv, with require "bundler/inline"
gemfile(true) do
source "https://rubygems.org"
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
gem "grape", "1.6.2"
end
require "grape"
class BaseAPI < Grape::API
end
class SomeAPI < Grape::API
route_setting :auth, public: true
namespace do
get '/a' do
end
route_setting :auth, public: true
get '/b' do
end
end
end
raise 'ERROR ON /a' if SomeAPI.routes.first.settings[:auth] != { public: true }
raise 'ERROR ON /b' if SomeAPI.routes.last.settings[:auth] != { public: true }
BaseAPI.mount SomeAPI
raise 'ERROR ON /a after mount' if SomeAPI.routes.first.settings[:auth] != { public: true }
raise 'ERROR ON /b after mount' if SomeAPI.routes.last.settings[:auth] != { public: true } |
The reason wrapping the DSL in an namespace (even blank) is working is because the DSL calls are only saved as step when they are at the root level of an Grape::API class. Once you put them in a namespace, they are not at root level, but in a block, and its this block that is "replayed"/re-called : the "setup steps" mechanism is skipped (except for the namespace call which is saved as the only "setup step" of the class, with a block to be re-called). |
I really don't understand why a Set is used for A Set is by definition NOT ordered. So there's a fundamental issue with using it : when setup steps are replayed, they are done so with a specific order in mind (an route description need to be called before But you can't rely on this behavior, because Set explicitly says that it doesn't guaranty ordering. We should rollback to an Array. I can put together a more fresh PR if there's any appetite for that. |
@Haerezis you're onto something - probably |
Closed via #2529. |
env
'value' work like frozen hash key. You can reproduce below code.
Second , 'route_setting' method calling doesn't work.
Anybody, can explain this situation?
route_setting work fine at ~> 1.4.0 on ruby 2.7
The text was updated successfully, but these errors were encountered: