Skip to content

Commit

Permalink
fix: Prevent infinite SystemActor creation
Browse files Browse the repository at this point in the history
Picked changes from b09ce59.
  • Loading branch information
ewuerger committed Sep 13, 2023
1 parent 80ca21b commit 91996a4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
20 changes: 17 additions & 3 deletions capella2polarion/elements/element.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from capellambse.model import diagram as diag

from capella2polarion import elements
from capella2polarion.elements import serialize
from capella2polarion.elements import helpers, serialize

logger = logging.getLogger(__name__)

Expand All @@ -28,11 +28,25 @@ def create_work_items(
) -> list[serialize.CapellaWorkItem]:
"""Create a set of work items in Polarion."""
objects = chain.from_iterable(ctx["ELEMENTS"].values())
work_items = [
_work_items = [
serialize.element(obj, ctx, serialize.generic_work_item)
for obj in objects
]
return list(filter(None.__ne__, work_items)) # type: ignore[arg-type]
_work_items = list(filter(None.__ne__, _work_items))
valid_types = set(map(helpers.resolve_element_type, set(ctx["ELEMENTS"])))
work_items: list[polarion_api.CapellaWorkItem] = []
missing_types: set[str] = set()
for work_item in _work_items:
assert work_item is not None
if work_item.type in valid_types:
work_items.append(work_item)
else:
missing_types.add(work_item.type)
logger.debug(
"%r are missing in the capella2polarion configuration",
", ".join(missing_types),
)
return work_items


def create_links(
Expand Down
2 changes: 2 additions & 0 deletions tests/test_elements.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,8 @@ def test_create_work_items(
monkeypatch: pytest.MonkeyPatch, context: dict[str, t.Any]
):
del context["ELEMENTS"]["UnsupportedFakeModelObject"]
context["MODEL"] = model = mock.MagicMock()
model.by_uuid.side_effect = context["ELEMENTS"]["FakeModelObject"]
monkeypatch.setattr(
serialize,
"generic_work_item",
Expand Down

0 comments on commit 91996a4

Please sign in to comment.