Skip to content
Open
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
38 changes: 30 additions & 8 deletions ingestion/src/metadata/ingestion/ometa/mixins/patch_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,24 @@
OWNER_TYPES: List[str] = ["user", "team"] # noqa: UP006


def _summarize_patch(patch: Any) -> str:
"""Return op count and `op:path` list for a JSON Patch, without values.

Values are intentionally excluded — they may contain descriptions, sample
data, or tag content that should not be logged.
"""
if patch is None:
return "<patch not built>"
try:
ops = json.loads(str(patch))
except (ValueError, TypeError):
return "<unparsable patch>"
if not isinstance(ops, list):
return "<patch is not a list>"
op_paths = [f"{op.get('op', '?')}:{op.get('path', '?')}" for op in ops if isinstance(op, dict)]
return f"{len(ops)} op(s) [{', '.join(op_paths)}]"


def convert_uuids_to_strings(obj: Any) -> Any:
"""
Recursively convert UUID objects to strings for JSON serialization
Expand Down Expand Up @@ -169,6 +187,7 @@
Returns
Updated Entity
"""
patch = None
try:
patch = build_patch(
source=source,
Expand All @@ -191,16 +210,19 @@

except Exception as exc:
logger.debug(traceback.format_exc())
patch_summary = _summarize_patch(patch)
entity_name = get_log_name(source)
if skip_on_failure:
entity_name = get_log_name(source)
logger.warning(f"Failed to update {entity_name}. The patch operation was skipped. Reason: {exc}")
logger.warning(
f"Failed to update {entity_name}. The patch operation was skipped. "
f"Reason: {exc} | Patch ops: {patch_summary}"
)
return None
else: # noqa: RET505
entity_name = get_log_name(source)
raise RuntimeError(
f"Failed to update {entity_name}. The patch operation failed. "
f"Set 'skip_on_failure=True' to skip failed patches. Error: {exc}"
) from exc
raise RuntimeError(
f"Failed to update {entity_name}. The patch operation failed. "
f"Set 'skip_on_failure=True' to skip failed patches. "
f"Error: {exc} | Patch ops: {patch_summary}"
) from exc

def patch_description(
self,
Expand Down Expand Up @@ -330,7 +352,7 @@
entity: Type[T], # noqa: UP006
source: T,
tag_labels: List[TagLabel], # noqa: UP006
operation: Union[PatchOperation.ADD, PatchOperation.REMOVE] = PatchOperation.ADD, # noqa: UP007

Check warning on line 355 in ingestion/src/metadata/ingestion/ometa/mixins/patch_mixin.py

View check run for this annotation

SonarQubeCloud / [open-metadata-ingestion] SonarCloud Code Analysis

Use a union type expression for this type hint.

See more on https://sonarcloud.io/project/issues?id=open-metadata-ingestion&issues=AZ3jGB0bPn-QGctdaL2u&open=AZ3jGB0bPn-QGctdaL2u&pullRequest=27692
skip_on_failure: bool = True,
) -> Optional[T]: # noqa: UP045
"""
Expand Down Expand Up @@ -385,7 +407,7 @@
entity: Type[T], # noqa: UP006
source: T,
tag_label: TagLabel,
operation: Union[PatchOperation.ADD, PatchOperation.REMOVE] = PatchOperation.ADD, # noqa: UP007

Check warning on line 410 in ingestion/src/metadata/ingestion/ometa/mixins/patch_mixin.py

View check run for this annotation

SonarQubeCloud / [open-metadata-ingestion] SonarCloud Code Analysis

Use a union type expression for this type hint.

See more on https://sonarcloud.io/project/issues?id=open-metadata-ingestion&issues=AZ3jGB0bPn-QGctdaL2v&open=AZ3jGB0bPn-QGctdaL2v&pullRequest=27692
skip_on_failure: bool = True,
) -> Optional[T]: # noqa: UP045
"""Will be deprecated in 1.3"""
Expand Down Expand Up @@ -494,7 +516,7 @@
self,
table: ClassifiableEntityType,
column_tags: List[ColumnTag], # noqa: UP006
operation: Union[PatchOperation.ADD, PatchOperation.REMOVE] = PatchOperation.ADD, # noqa: UP007

Check warning on line 519 in ingestion/src/metadata/ingestion/ometa/mixins/patch_mixin.py

View check run for this annotation

SonarQubeCloud / [open-metadata-ingestion] SonarCloud Code Analysis

Use a union type expression for this type hint.

See more on https://sonarcloud.io/project/issues?id=open-metadata-ingestion&issues=AZ3jGB0bPn-QGctdaL2w&open=AZ3jGB0bPn-QGctdaL2w&pullRequest=27692
) -> Optional[T]: # noqa: UP045
"""Given an Entity ID, JSON PATCH the tag of the column

Expand Down Expand Up @@ -533,7 +555,7 @@
table: Table,
column_fqn: str,
tag_label: TagLabel,
operation: Union[PatchOperation.ADD, PatchOperation.REMOVE] = PatchOperation.ADD, # noqa: UP007

Check warning on line 558 in ingestion/src/metadata/ingestion/ometa/mixins/patch_mixin.py

View check run for this annotation

SonarQubeCloud / [open-metadata-ingestion] SonarCloud Code Analysis

Use a union type expression for this type hint.

See more on https://sonarcloud.io/project/issues?id=open-metadata-ingestion&issues=AZ3jGB0bPn-QGctdaL2x&open=AZ3jGB0bPn-QGctdaL2x&pullRequest=27692
) -> Optional[T]: # noqa: UP045
"""Will be deprecated in 1.3"""
return self.patch_column_tags(
Expand Down Expand Up @@ -606,7 +628,7 @@
def patch_automation_workflow_response(
self,
automation_workflow: AutomationWorkflow,
result: Union[TestConnectionResult, ReverseIngestionResponse, QueryRunnerResponse], # noqa: UP007

Check warning on line 631 in ingestion/src/metadata/ingestion/ometa/mixins/patch_mixin.py

View check run for this annotation

SonarQubeCloud / [open-metadata-ingestion] SonarCloud Code Analysis

Use a union type expression for this type hint.

See more on https://sonarcloud.io/project/issues?id=open-metadata-ingestion&issues=AZ3jGB0bPn-QGctdaL2y&open=AZ3jGB0bPn-QGctdaL2y&pullRequest=27692
workflow_status: WorkflowStatus,
) -> None:
"""
Expand Down Expand Up @@ -701,7 +723,7 @@
def patch_custom_properties(
self,
entity: Type[T], # noqa: UP006
entity_id: Union[str, basic.Uuid], # noqa: UP007

Check warning on line 726 in ingestion/src/metadata/ingestion/ometa/mixins/patch_mixin.py

View check run for this annotation

SonarQubeCloud / [open-metadata-ingestion] SonarCloud Code Analysis

Use a union type expression for this type hint.

See more on https://sonarcloud.io/project/issues?id=open-metadata-ingestion&issues=AZ3jGB0bPn-QGctdaL2z&open=AZ3jGB0bPn-QGctdaL2z&pullRequest=27692
custom_properties: Dict[str, Any], # noqa: UP006
force: bool = False,
) -> Optional[T]: # noqa: UP045
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,8 @@ public static <T> T applyPatch(T original, JsonPatch patch, Class<T> clz) {
JsonNode jsonNode = OBJECT_MAPPER.readTree(jsonString);
return OBJECT_MAPPER.convertValue(jsonNode, clz);
} catch (Exception e) {
throw new RuntimeException("Failed to convert JsonValue to target class", e);
throw new RuntimeException(
"Failed to convert JsonValue to " + clz.getSimpleName() + ": " + e.getMessage(), e);
}
}

Expand Down
Loading