mirror of
https://github.com/datahub-project/datahub.git
synced 2025-10-13 09:54:10 +00:00
fix(ingest): Call validator on the base urn as well as aspect components when ingesting (#8250)
Co-authored-by: Indy Prentice <indy@Indys-MacBook-Pro.local>
This commit is contained in:
parent
d1ff9024b9
commit
e35ac44f58
@ -10,6 +10,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
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;
|
||||
@ -24,6 +25,7 @@ import com.linkedin.common.urn.UrnUtils;
|
||||
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;
|
||||
@ -563,10 +565,11 @@ public class EntityService {
|
||||
}
|
||||
|
||||
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
|
||||
@ -697,6 +700,7 @@ public class EntityService {
|
||||
return systemMetadata;
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
static void validateUrn(@Nonnull final Urn urn) {
|
||||
|
||||
if (urn.toString().trim().length() != urn.toString().length()) {
|
||||
|
@ -1215,12 +1215,9 @@ abstract public class EntityServiceTest<T_AD extends AspectDao, T_RS extends Ret
|
||||
}
|
||||
|
||||
// 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");
|
||||
|
@ -56,4 +56,4 @@
|
||||
"priority": 100
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user