-
Notifications
You must be signed in to change notification settings - Fork 58
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
Fix silent failure when ingesting an Asset with an unrecognized field #481
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #481 +/- ##
============================================
+ Coverage 66.21% 66.25% +0.03%
- Complexity 1531 1532 +1
============================================
Files 137 137
Lines 5888 5889 +1
Branches 653 653
============================================
+ Hits 3899 3902 +3
+ Misses 1711 1710 -1
+ Partials 278 277 -1 ☔ View full report in Codecov by Sentry. |
*/ | ||
public static void validateAgainstSchema(@Nonnull RecordTemplate model) { | ||
ValidationResult result = ValidateDataAgainstSchema.validate(model, | ||
new ValidationOptions(RequiredMode.CAN_BE_ABSENT_IF_HAS_DEFAULT, CoercionMode.NORMAL, |
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.
can ValidationOptions be a constant? or it has to be instantiated every time?
new ValidationOptions(RequiredMode.CAN_BE_ABSENT_IF_HAS_DEFAULT, CoercionMode.NORMAL, | ||
UnrecognizedFieldMode.DISALLOW)); | ||
if (!result.isValid()) { | ||
invalidSchema(result.getMessages().toString()); |
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.
using String.valueOf(result.getMessages())
to avoid NPE?
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.
Minor comments, thanks for making the improvements!
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.
LGTM!
@@ -46,6 +46,9 @@ public final class ValidationUtils { | |||
|
|||
private static final Map<String, String> SOFT_DELETED_FIELD_METADATA = fieldMetadata(new SoftDeletedAspect().schema()); | |||
|
|||
public static final ValidationOptions VALIDATION_OPTIONS = |
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.
minor: make it private if not used in other class
Summary
BUG=META-21242
This PR adds Restli model validation to the Asset ingestion endpoints to throw errors in these otherwise silent-failure cases:
Testing Done
Added unit testing for both:
Checklist