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

MINOR: Fix description and tags update from ingestion patch #14305

Merged
merged 1 commit into from
Dec 7, 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
6 changes: 6 additions & 0 deletions ingestion/src/metadata/ingestion/models/patch_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ class PatchRequest(BaseModel):
"name": True,
"dataType": True,
"arrayDataType": True,
"description": True,
"tags": True,
"dataLength": True,
"constraint": True,
"children": True,
Expand Down Expand Up @@ -62,6 +64,8 @@ class PatchRequest(BaseModel):
"name": True,
"displayName": True,
"sourceUrl": True,
"description": True,
"tags": True,
# Table Entity Fields
"tableType": True,
"columns": {"__all__": ALLOWED_COLUMN_FIELDS},
Expand Down Expand Up @@ -116,3 +120,5 @@ class PatchRequest(BaseModel):
"size": True,
"fileFormats": True,
}

RESTRICT_UPDATE_LIST = ["description", "tags"]
28 changes: 28 additions & 0 deletions ingestion/src/metadata/ingestion/ometa/mixins/patch_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ def patch(
source: T,
destination: T,
allowed_fields: Optional[Dict] = None,
restrict_update_fields: Optional[List] = None,
) -> Optional[T]:
"""
Given an Entity type and Source entity and Destination entity,
Expand All @@ -129,6 +130,8 @@ def patch(
entity (T): Entity Type
source: Source payload which is current state of the source in OpenMetadata
destination: payload with changes applied to the source.
allowed_fields: List of field names to filter from source and destination models
restrict_update_fields: List of field names which will only support add operation

Returns
Updated Entity
Expand Down Expand Up @@ -169,6 +172,18 @@ def patch(
)
return None

# for a user editable fields like descriptions, tags we only want to support "add" operation in patch
# we will remove the other operations for replace, remove from here
if restrict_update_fields:
patch.patch = [
patch_ops
for patch_ops in patch.patch
if self._determine_restricted_operation(
patch_ops=patch_ops,
restrict_update_fields=restrict_update_fields,
)
]

res = self.client.patch(
path=f"{self.get_suffix(entity)}/{model_str(source.id)}",
data=str(patch),
Expand All @@ -183,6 +198,19 @@ def patch(

return None

def _determine_restricted_operation(
self, patch_ops: Dict, restrict_update_fields: Optional[List] = None
) -> bool:
"""
Only retain add operation for restrict_update_fields fields
"""
path = patch_ops.get("path")
op = patch_ops.get("op")
for field in restrict_update_fields or []:
if field in path and op != PatchOperation.ADD.value:
return False
return True

def patch_description(
self,
entity: Type[T],
Expand Down
2 changes: 2 additions & 0 deletions ingestion/src/metadata/ingestion/sink/metadata_rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
from metadata.ingestion.models.ometa_topic_data import OMetaTopicSampleData
from metadata.ingestion.models.patch_request import (
ALLOWED_COMMON_PATCH_FIELDS,
RESTRICT_UPDATE_LIST,
PatchRequest,
)
from metadata.ingestion.models.pipeline_status import OMetaPipelineStatus
Expand Down Expand Up @@ -167,6 +168,7 @@ def patch_entity(self, record: PatchRequest) -> Either[Entity]:
source=record.original_entity,
destination=record.new_entity,
allowed_fields=ALLOWED_COMMON_PATCH_FIELDS,
restrict_update_fields=RESTRICT_UPDATE_LIST,
)
return Either(right=entity)

Expand Down
Loading