Allow dynamic constraint validation messages#2246
Merged
arteam merged 1 commit intodropwizard:masterfrom Jan 18, 2018
Merged
Conversation
Previously, once a validation constraint was evaluated the entire string
was cached. The impetus for a cache is that reflection is used to
determine if we need to prefix an error message with additional context
(eg. "query parameter x ..."). Repeatedly calculating this prefix is
wasteful -- thus the cache was born.
The biggest issue with this cache is that while it worked with all
Hibernate Validation default message templates, it failed for message
templates that contained the invalid value (eg. "query parameter x
({validatedValue}) is greater than {value}"), as the same error would be
returned regardless of validatedValue. It would also fail for custom
constraint validators that didn't return the same message everytime.
The fix is to switch the cache from caching the entire error message to
just the error prefix (eg. "query parameter x", "return value", no
prefix).
This has no effect on performance and will allow custom validation
messages in Dropwizard.
Member
|
LGTM! |
arteam
pushed a commit
that referenced
this pull request
Jan 18, 2018
Previously, once a validation constraint was evaluated the entire string
was cached. The impetus for a cache is that reflection is used to
determine if we need to prefix an error message with additional context
(eg. "query parameter x ..."). Repeatedly calculating this prefix is
wasteful -- thus the cache was born.
The biggest issue with this cache is that while it worked with all
Hibernate Validation default message templates, it failed for message
templates that contained the invalid value (eg. "query parameter x
({validatedValue}) is greater than {value}"), as the same error would be
returned regardless of validatedValue. It would also fail for custom
constraint validators that didn't return the same message everytime.
The fix is to switch the cache from caching the entire error message to
just the error prefix (eg. "query parameter x", "return value", no
prefix).
This has no effect on performance and will allow custom validation
messages in Dropwizard.
(cherry picked from commit 2c1609b)
Member
|
Applied to 1.2.x as 76ebbb0 |
Contributor
Author
|
Hey @arteam, I realize now that the PR title "Constraint validation caches error prefixes" may not give dropwizard users an apt description of what changes for them. Maybe something along the lines of "Allow dynamic constraint validation messages" should be in the release notes / new title of this PR. |
Member
|
Sounds good. I've changed the release notes for 1.3.0-rc4 and the name of the issue. |
aaanders
pushed a commit
to aaanders/dropwizard
that referenced
this pull request
Sep 20, 2018
Previously, once a validation constraint was evaluated the entire string
was cached. The impetus for a cache is that reflection is used to
determine if we need to prefix an error message with additional context
(eg. "query parameter x ..."). Repeatedly calculating this prefix is
wasteful -- thus the cache was born.
The biggest issue with this cache is that while it worked with all
Hibernate Validation default message templates, it failed for message
templates that contained the invalid value (eg. "query parameter x
({validatedValue}) is greater than {value}"), as the same error would be
returned regardless of validatedValue. It would also fail for custom
constraint validators that didn't return the same message everytime.
The fix is to switch the cache from caching the entire error message to
just the error prefix (eg. "query parameter x", "return value", no
prefix).
This has no effect on performance and will allow custom validation
messages in Dropwizard.
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.
Previously, once a validation constraint was evaluated the entire string
was cached. The impetus for a cache is that reflection is used to
determine if we need to prefix an error message with additional context
(eg. "query parameter x ..."). Repeatedly calculating this prefix is
wasteful -- thus the cache was born.
The biggest issue with this cache is that while it worked with all
Hibernate Validation default message templates, it failed for message
templates that contained the invalid value (eg. "query parameter x
({validatedValue}) is greater than {value}"), as the same error would be
returned regardless of validatedValue. It would also fail for custom
constraint validators that didn't return the same message everytime.
The fix is to switch the cache from caching the entire error message to
just the error prefix (eg. "query parameter x", "return value", no
prefix).
This has no effect on performance and will allow for more
custom validation messages in Dropwizard.
Closes #2245
Ref #2090
CC'ing users who expressed interest: @imochurad @rtti @peterklijn