Skip to content
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

Merged
merged 6 commits into from
Nov 27, 2024

Conversation

jphui
Copy link
Contributor

@jphui jphui commented Nov 27, 2024

Summary

BUG=META-21242

This PR adds Restli model validation to the Asset ingestion endpoints to throw errors in these otherwise silent-failure cases:

  1. curli calls with fields that are simply not a part of the model, these should error out!
  2. (java) client calls with a newer bump to metadata-models that contain NEW fields that are not recognized by the server, these should also error out!

Testing Done

Added unit testing for both:

  1. parent utility class
  2. BaseEntityResource, which is where ingestion is invoked at the API layer

Checklist

@codecov-commenter
Copy link

codecov-commenter commented Nov 27, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 66.25%. Comparing base (5261abf) to head (4e0951e).

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.
📢 Have feedback on the report? Share it here.

*/
public static void validateAgainstSchema(@Nonnull RecordTemplate model) {
ValidationResult result = ValidateDataAgainstSchema.validate(model,
new ValidationOptions(RequiredMode.CAN_BE_ABSENT_IF_HAS_DEFAULT, CoercionMode.NORMAL,
Copy link
Contributor

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());
Copy link
Contributor

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?

Copy link
Contributor

@yangyangv2 yangyangv2 left a 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!

Copy link
Contributor

@yangyangv2 yangyangv2 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@jphui jphui merged commit 783ae91 into master Nov 27, 2024
2 checks passed
@@ -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 =
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants