-
-
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
fixes configuration inside namespaced params scope #2152
fixes configuration inside namespaced params scope #2152
Conversation
@@ -39,7 +39,7 @@ def initialize(opts, &block) | |||
end | |||
|
|||
def configuration | |||
@api.configuration.evaluate | |||
@api.configuration.respond_to?(:evaluate) ? @api.configuration.evaluate : @api.configuration |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This works, but I worry that we're having something together. How do we end up here? What do we end up having here as @api.configuration
? What's the call stack?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi there dblock :)
This is the callstack without namespace
"lib/grape/validations/params_scope.rb:42:in `configuration'",
"lib/grape/validations/params_scope.rb:36:in `instance_eval'",
"lib/grape/validations/params_scope.rb:36:in `initialize'",
"lib/grape/dsl/validations.rb:42:in `new'",
"lib/grape/dsl/validations.rb:42:in `params'",
"lib/grape/api.rb:155:in `replay_step_on'",
"lib/grape/api.rb:105:in `block in replay_setup_on'",
"ruby/2.7.1/lib/ruby/2.7.0/set.rb:328:in `each_key'",
"ruby/2.7.1/lib/ruby/2.7.0/set.rb:328:in `each'",
"lib/grape/api.rb:104:in `replay_setup_on'",
"lib/grape/api.rb:97:in `mount_instance'",
"lib/grape/dsl/routing.rb:87:in `block in mount'",
"lib/grape/dsl/routing.rb:84:in `each_pair'",
"lib/grape/dsl/routing.rb:84:in `mount'",
"lib/grape/api.rb:155:in `replay_step_on'",
"lib/grape/api.rb:147:in `block in add_setup'",
"lib/grape/api.rb:146:in `each'",
"lib/grape/api.rb:146:in `add_setup'",
"lib/grape/api.rb:42:in `block (2 levels) in override_all_methods!'",
and with namespace
"lib/grape/validations/params_scope.rb:42:in `configuration'",
"lib/grape/validations/params_scope.rb:36:in `instance_eval'",
"lib/grape/validations/params_scope.rb:36:in `initialize'",
"lib/grape/dsl/validations.rb:42:in `new'",
"lib/grape/dsl/validations.rb:42:in `params'",
"lib/grape/api/instance.rb:120:in `instance_eval'",
"lib/grape/api/instance.rb:120:in `block in evaluate_as_instance_with_configuration'",
"lib/grape/util/lazy_block.rb:11:in `evaluate_from'",
"lib/grape/api/instance.rb:127:in `evaluate_as_instance_with_configuration'",
"lib/grape/api/instance.rb:107:in `block in nest'",
"lib/grape/api/instance.rb:107:in `each'",
"lib/grape/api/instance.rb:107:in `nest'",
"lib/grape/dsl/routing.rb:173:in `block in namespace'",
"lib/grape/dsl/settings.rb:160:in `within_namespace'",
"lib/grape/dsl/routing.rb:170:in `namespace'",
"lib/grape/api.rb:155:in `replay_step_on'",
"lib/grape/api.rb:105:in `block in replay_setup_on'",
"ruby/2.7.1/lib/ruby/2.7.0/set.rb:328:in `each_key'",
"ruby/2.7.1/lib/ruby/2.7.0/set.rb:328:in `each'",
"lib/grape/api.rb:104:in `replay_setup_on'",
"lib/grape/api.rb:97:in `mount_instance'",
"lib/grape/dsl/routing.rb:87:in `block in mount'",
"lib/grape/dsl/routing.rb:84:in `each_pair'",
"lib/grape/dsl/routing.rb:84:in `mount'",
"lib/grape/api.rb:155:in `replay_step_on'",
"lib/grape/api.rb:147:in `block in add_setup'",
"lib/grape/api.rb:146:in `each'",
"lib/grape/api.rb:146:in `add_setup'",
"lib/grape/api.rb:42:in `block (2 levels) in override_all_methods!'",
the configuration gets evaluated in this step
"lib/grape/api/instance.rb:127:in
evaluate_as_instance_with_configuration'`
def evaluate_as_instance_with_configuration(block, lazy: false)
lazy_block = Grape::Util::LazyBlock.new do |configuration|
value_for_configuration = configuration
if value_for_configuration.respond_to?(:lazy?) && value_for_configuration.lazy?
self.configuration = value_for_configuration.evaluate
end
#...
end
end
but this does not answer your question. I am not familiar with the internals of the gem and I can imagine that changing how those lazy evaluations flow might lead to performance issues or other side-effects...
To me it seems that this would be a safe patch since the configuration has already been evaluated anyway but it is probably not addressing the underlying issue
We do something similar elsewhere, Line 54 in 02d7113
|
fixes #2154