Open
Conversation
Danger ReportNo issues found. |
5d145a5 to
f87920f
Compare
Contributor
Author
|
Missing UPGRADING notes. Working on it |
2ecb403 to
cf04c9d
Compare
Member
|
Is there a tradeoff with things like |
Contributor
Author
e16efcf to
0b9e34b
Compare
a503556 to
2b16ba1
Compare
52b7862 to
adac9ed
Compare
2a39a4d to
2d51b32
Compare
177506d to
c4df5d3
Compare
Contributor
Author
Code reviewFound 2 issues:
Lines 1 to 5 in c4df5d3
Lines 208 to 217 in c4df5d3 🤖 Generated with Claude Code If this code review was useful, please react with 👍. Otherwise, react with 👎. |
0a19583 to
d1e35a1
Compare
dblock
requested changes
Mar 21, 2026
Member
dblock
left a comment
There was a problem hiding this comment.
Nice work. I think deep_freeze can't return on obj.frozen?.
|
|
||
| #### Custom validators: use `default_message_key` and `validation_error!` | ||
|
|
||
| Validators are now instantiated once at definition time and frozen. Any setup should happen in `initialize`, not in `validate_param!`. |
Member
There was a problem hiding this comment.
So will users have to rewrite custom validators? Explain how if so with a simple example.
Validators are now instantiated once at route definition time and frozen, rather than per-request via ValidatorFactory. This removes repeated object allocation from the hot path and moves option parsing, converter building, and message formatting into initialize. - Remove ValidatorFactory; ParamsScope#validate instantiates validators directly - Freeze validator instances via Base.new override (super.freeze) - Add Grape::Util::DeepFreeze to recursively freeze Hash/Array/String options - Freeze ParamsScope at end of initialize; cache full_path as @full_path - Promote validate_param! to protected with NotImplementedError default - Extract validation_error!, hash_like?, option_value, scrub helpers in Base - Add default_message_key class macro for pre-computing exception messages - Eager-initialize all built-in validators (coerce, default, values, regexp, etc.) - ContractScopeValidator no longer inherits Base (standalone with freeze) - coerce_type receives only extracted coerce keys; callers skip manual deletes - Add DeepFreeze spec; add SameAsValidator and ExceptValuesValidator specs Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Validators are now instantiated once at route definition time rather than per-request via `ValidatorFactory`. This eliminates repeated object allocation on every request and moves expensive setup (option parsing, converter building, message formatting) out of the hot path.
Because validator instances are shared across all concurrent requests they are frozen after initialization, enforced by a `Validators::Base.new` override that calls `super.freeze`. All inputs (`options`, `opts`, `attrs`) arrive pre-frozen from the DSL boundary via `DeepFreeze` and `Array#freeze`, so subclass ivars derived from them are frozen by construction. A new `Grape::Util::DeepFreeze` helper recursively freezes Hash/Array/String values while intentionally leaving Procs, coercers, Classes, and other mutable objects unfrozen.
Fix #2519
Changes
Core
`Validators::Base`
`Grape::Util::DeepFreeze`
Validator-level eager initialization
Specs
Test plan