Skip to content

Commit

Permalink
fix(ingest): Call validator on the base urn as well as aspect compone…
Browse files Browse the repository at this point in the history
…nts when ingesting (datahub-project#8250)

Co-authored-by: Indy Prentice <[email protected]>
  • Loading branch information
2 people authored and tusharm committed Jun 20, 2023
1 parent 80db625 commit b350872
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.github.fge.jsonpatch.JsonPatch;
import com.github.fge.jsonpatch.JsonPatchException;
import com.github.fge.jsonpatch.Patch;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterators;
Expand All @@ -24,6 +25,7 @@
import com.linkedin.common.urn.VersionedUrnUtils;
import com.linkedin.data.schema.RecordDataSchema;
import com.linkedin.data.schema.TyperefDataSchema;
import com.linkedin.data.schema.validation.ValidationResult;
import com.linkedin.data.schema.validator.Validator;
import com.linkedin.data.template.DataTemplateUtil;
import com.linkedin.data.template.RecordTemplate;
Expand Down Expand Up @@ -563,10 +565,11 @@ private void validateAspect(Urn urn, RecordTemplate aspect) {
}

private void validateAspect(Urn urn, RecordTemplate aspect, Validator validator) {
RecordTemplateValidator.validate(aspect, validationResult -> {
Consumer<ValidationResult> resultFunction = validationResult -> {
throw new IllegalArgumentException("Invalid format for aspect: " + aspect + " for entity: " + urn + "\n Cause: "
+ validationResult.getMessages());
}, validator);
+ validationResult.getMessages()); };
RecordTemplateValidator.validate(buildKeyAspect(urn), resultFunction, validator);
RecordTemplateValidator.validate(aspect, resultFunction, validator);
}
/**
* Checks whether there is an actual update to the aspect by applying the updateLambda
Expand Down Expand Up @@ -697,6 +700,7 @@ protected SystemMetadata generateSystemMetadataIfEmpty(@Nullable SystemMetadata
return systemMetadata;
}

@VisibleForTesting
static void validateUrn(@Nonnull final Urn urn) {

if (urn.toString().trim().length() != urn.toString().length()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1215,12 +1215,9 @@ public void testValidateUrn() throws Exception {
}

// Urn purely too long
StringBuilder buildStringTooLong = new StringBuilder();
for (int i = 0; i < 510; i++) {
buildStringTooLong.append('a');
}
String stringTooLong = "a".repeat(510);

Urn testUrnTooLong = new Urn("li", "testType", new TupleKey(buildStringTooLong.toString()));
Urn testUrnTooLong = new Urn("li", "testType", new TupleKey(stringTooLong));
try {
EntityService.validateUrn(testUrnTooLong);
Assert.fail("Should have raised IllegalArgumentException for URN too long");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,4 @@
"priority": 100
}
}
}
}

0 comments on commit b350872

Please sign in to comment.