Skip to content

Commit ec1b0fe

Browse files
authored
Merge pull request #2667 from ruby-grape/skip_instrumentation_no_validators
Skip instrumentation in run_validators when no validators present
2 parents e98757c + 586641f commit ec1b0fe

4 files changed

Lines changed: 7 additions & 6 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
* [#2664](https://github.com/ruby-grape/grape/pull/2664): Drop `test-prof` dependency - [@ericproulx](https://github.com/ericproulx).
1010
* [#2665](https://github.com/ruby-grape/grape/pull/2665): Pass `attrs` directly to `AttributesIterator` instead of `validator` - [@ericproulx](https://github.com/ericproulx).
1111
* [#2657](https://github.com/ruby-grape/grape/pull/2657): Instantiate validators at definition time - [@ericproulx](https://github.com/ericproulx).
12+
* [#2667](https://github.com/ruby-grape/grape/pull/2667): Skip instrumentation in run_validators when no validators present - [@ericproulx](https://github.com/ericproulx).
1213
* Your contribution here.
1314

1415
#### Fixes

UPGRADING.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ Upgrading Grape
33

44
### Upgrading to >= 3.2
55

6+
#### `endpoint_run_validators.grape` notification no longer fired when there are no validators
7+
8+
`ActiveSupport::Notifications` subscribers listening to `endpoint_run_validators.grape` will no longer receive an event for endpoints that have no validators. If you rely on this notification to measure every request, subscribe to `endpoint_run.grape` instead, which always fires.
9+
610
#### Custom validators: use `default_message_key` and `validation_error!`
711

812
Validators are now instantiated once at definition time and frozen. Any setup should happen in `initialize`, not in `validate_param!`.

lib/grape/endpoint.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,8 @@ def execute
205205

206206
def run_validators(request:)
207207
validators = inheritable_setting.route[:saved_validations]
208+
return if validators.empty?
209+
208210
validation_errors = []
209211

210212
Grape::Validations::ParamScopeTracker.track do

spec/grape/endpoint_spec.rb

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1062,9 +1062,6 @@ def memoized
10621062
have_attributes(name: 'endpoint_run_filters.grape', payload: { endpoint: a_kind_of(described_class),
10631063
filters: [],
10641064
type: :before_validation }),
1065-
have_attributes(name: 'endpoint_run_validators.grape', payload: { endpoint: a_kind_of(described_class),
1066-
validators: [],
1067-
request: a_kind_of(Grape::Request) }),
10681065
have_attributes(name: 'endpoint_run_filters.grape', payload: { endpoint: a_kind_of(described_class),
10691066
filters: [],
10701067
type: :after_validation }),
@@ -1091,9 +1088,6 @@ def memoized
10911088
have_attributes(name: 'endpoint_run_filters.grape', payload: { endpoint: a_kind_of(described_class),
10921089
filters: [],
10931090
type: :before_validation }),
1094-
have_attributes(name: 'endpoint_run_validators.grape', payload: { endpoint: a_kind_of(described_class),
1095-
validators: [],
1096-
request: a_kind_of(Grape::Request) }),
10971091
have_attributes(name: 'endpoint_run_filters.grape', payload: { endpoint: a_kind_of(described_class),
10981092
filters: [],
10991093
type: :after_validation }),

0 commit comments

Comments
 (0)