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): avrogen handling for missing fields with default values #5844

Merged
merged 1 commit into from
Sep 8, 2022
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
2 changes: 1 addition & 1 deletion metadata-ingestion/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def get_long_description():
"entrypoints",
"docker",
"expandvars>=0.6.5",
"avro-gen3==0.7.5",
"avro-gen3==0.7.6",
# "avro-gen3 @ git+https://github.com/acryldata/avro_gen@master#egg=avro-gen3",
"avro>=1.10.2,<1.11",
"python-dateutil>=2.8.0",
Expand Down
50 changes: 50 additions & 0 deletions metadata-ingestion/tests/unit/serde/test_serde.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,3 +238,53 @@ def test_null_hiding() -> None:
"recursive": False,
"type": {"type": {"com.linkedin.pegasus2avro.schema.StringType": {}}},
}


def test_missing_optional_simple() -> None:
original = models.DataHubResourceFilterClass.from_obj(
{
"allResources": False,
"filter": {
"criteria": [
{
"condition": "EQUALS",
"field": "RESOURCE_TYPE",
"values": ["notebook", "dataset", "dashboard"],
}
]
},
}
)

# This one is missing the optional filters.allResources field.
revised_obj = {
"filter": {
"criteria": [
{
"condition": "EQUALS",
"field": "RESOURCE_TYPE",
"values": ["notebook", "dataset", "dashboard"],
}
]
},
}
revised = models.DataHubResourceFilterClass.from_obj(revised_obj)
assert revised.validate()

assert original == revised


def test_missing_optional_in_union() -> None:
# This one doesn't contain any optional fields and should work fine.
revised_json = json.loads(
'{"lastUpdatedTimestamp":1662356745807,"actors":{"groups":[],"resourceOwners":false,"allUsers":true,"allGroups":false,"users":[]},"privileges":["EDIT_ENTITY_ASSERTIONS","EDIT_DATASET_COL_GLOSSARY_TERMS","EDIT_DATASET_COL_TAGS","EDIT_DATASET_COL_DESCRIPTION"],"displayName":"customtest","resources":{"filter":{"criteria":[{"field":"RESOURCE_TYPE","condition":"EQUALS","values":["notebook","dataset","dashboard"]}]},"allResources":false},"description":"","state":"ACTIVE","type":"METADATA"}'
)
revised = models.DataHubPolicyInfoClass.from_obj(revised_json)

# This one is missing the optional filters.allResources field.
original_json = json.loads(
'{"privileges":["EDIT_ENTITY_ASSERTIONS","EDIT_DATASET_COL_GLOSSARY_TERMS","EDIT_DATASET_COL_TAGS","EDIT_DATASET_COL_DESCRIPTION"],"actors":{"resourceOwners":false,"groups":[],"allGroups":false,"allUsers":true,"users":[]},"lastUpdatedTimestamp":1662356745807,"displayName":"customtest","description":"","resources":{"filter":{"criteria":[{"field":"RESOURCE_TYPE","condition":"EQUALS","values":["notebook","dataset","dashboard"]}]}},"state":"ACTIVE","type":"METADATA"}'
)
original = models.DataHubPolicyInfoClass.from_obj(original_json)

assert revised == original