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(ingest): Call validator on the base urn as well as aspect components when ingesting #8250

Merged
merged 4 commits into from
Jun 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -25,6 +26,7 @@
import com.linkedin.data.DataMap;
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 @@ -556,10 +558,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 @@ -690,6 +693,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 @@ -1213,12 +1213,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
}
}
}
}