From 494fa84c58b0040ffdc718e8d39ebcd2b0cbfd20 Mon Sep 17 00:00:00 2001 From: ewuerger Date: Mon, 9 Dec 2024 12:13:47 +0100 Subject: [PATCH] fix!: Remove `width` and `height` from ELK input data --- .../data_model/work_item_attachments.py | 34 +++++++++++++++++-- tests/test_workitem_attachments.py | 2 +- 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/capella2polarion/data_model/work_item_attachments.py b/capella2polarion/data_model/work_item_attachments.py index 62f2add..f726060 100644 --- a/capella2polarion/data_model/work_item_attachments.py +++ b/capella2polarion/data_model/work_item_attachments.py @@ -1,9 +1,11 @@ # Copyright DB InfraGO AG and contributors # SPDX-License-Identifier: Apache-2.0 """Module providing the CapellaWorkItemAttachment classes.""" + from __future__ import annotations import base64 +import copy import dataclasses import hashlib import logging @@ -12,7 +14,7 @@ import cairosvg import polarion_rest_api_client as polarion_api from capellambse import model -from capellambse_context_diagrams import context +from capellambse_context_diagrams import _elkjs, context SVG_MIME_TYPE = "image/svg+xml" PNG_MIME_TYPE = "image/png" @@ -116,9 +118,15 @@ def content_checksum(self) -> str: try: elk_input = self.diagram.elk_input_data(self.render_params) if isinstance(elk_input, tuple): - input_str = ";".join(eit.json() for eit in elk_input) + input_str = ";".join( + remove_width_and_height(eit).model_dump_json() + for eit in elk_input + ) else: - input_str = elk_input.json() + input_str = remove_width_and_height( + elk_input + ).model_dump_json() + self._checksum = hashlib.sha256( input_str.encode("utf-8") ).hexdigest() @@ -134,6 +142,26 @@ def content_checksum(self) -> str: return self._checksum +def remove_width_and_height( + elk_input: _elkjs.ELKInputData, +) -> _elkjs.ELKInputData: + """Remove width and height from all elements in elk input.""" + + def process_item(item): + if hasattr(item, "width"): + del item.width + if hasattr(item, "height"): + del item.height + + for attr in ("children", "edges", "ports", "labels"): + for element in getattr(item, attr, []): + process_item(element) + + elk_input_copy = copy.deepcopy(elk_input) + process_item(elk_input_copy) + return elk_input_copy + + class PngConvertedSvgAttachment(Capella2PolarionAttachment): """A special attachment type for PNGs which shall be created from SVGs. diff --git a/tests/test_workitem_attachments.py b/tests/test_workitem_attachments.py index 28c0fe8..51014c9 100644 --- a/tests/test_workitem_attachments.py +++ b/tests/test_workitem_attachments.py @@ -35,7 +35,7 @@ "0ed1417e8e4717524bc91162dcf8633afca686e93f8b036d0bc48d81f0444f56" ) CONTEXT_DIAGRAM_CHECKSUM = ( - "572cb7ba53bcde56638a119fafc1304af294467d8c851f4b2cc35ce2f5d231eb" + "a26f4fc31c6c1c3b96d5725fa727cfd5f8651bec68faf04c8113359855bf5461" ) TEST_DIAG_UUID = "_APOQ0QPhEeynfbzU12yy7w"