Skip to content

ATLAS-2933:Empty array attributes are returned as null instead of an empty list#29

Closed
mahaha000 wants to merge 1 commit intoapache:masterfrom
mahaha000:lma_master
Closed

ATLAS-2933:Empty array attributes are returned as null instead of an empty list#29
mahaha000 wants to merge 1 commit intoapache:masterfrom
mahaha000:lma_master

Conversation

@mahaha000
Copy link
Copy Markdown
Contributor

Empty array attributes are returned as null instead of an empty list

@@ -207,12 +207,15 @@ public static <T extends AtlasElement> void setProperty(T element, String proper
Object existingValue = element.getProperty(propertyName, Object.class);

if (value == null || (value instanceof Collection && ((Collection)value).isEmpty())) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Consider the following alternate, for easier readability:

if (value == null) {
  if (existingValue != null) {
    if (LOG.isDebugEnabled()) {
      LOG.debug("Removing property {} from {}", propertyName, toString(element));
    }

    element.removeProperty(propertyName);
  }
} else {
  element.setProperty(propertyName, value);
}

return softRefVal;
}

if (CollectionUtils.isNotEmpty(softRefVal)) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

replace line #732 with: "else {", as the reverse condition is already tested in line #728 above.

complexEntity.setAttribute("listOfStructs", null);
AtlasEntitiesWithExtInfo complexEntityInfo = new AtlasEntitiesWithExtInfo(complexEntity);
EntityMutationResponse responseUpdated = entityStore.createOrUpdate(new AtlasEntityStream(complexEntityInfo), false);
AtlasEntityHeader updatedComplexEntity = responseUpdated.getFirstUpdatedEntityByTypeName(ENTITY_TYPE_WITH_COMPLEX_COLLECTION_ATTR);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

updatedComplexEntity is a AtlasEntityHeader - which will not have all attributes of an entity, hence the asset at line #235 passes. Please get an entire entity and use that in assert:

  AtlasEntityHeader      updatedEntityHeader  = responseUpdated.getFirstUpdatedEntityByTypeName(ENTITY_TYPE_WITH_COMPLEX_COLLECTION_ATTR);
  AtlasEntity            updatedComplexEntity = getEntityFromStore(updatedEntityHeader);
  Object                 updatedAttrValue     = updatedComplexEntity.getAttribute("listOfStructs");

  assertNull(updatedAttrValue, "listOfStructs");

@nixonrodrigues
Copy link
Copy Markdown
Collaborator

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