Skip to content

Commit 25102b5

Browse files
committed
fix a bug with product mappings
1 parent 099e694 commit 25102b5

File tree

3 files changed

+23
-14
lines changed

3 files changed

+23
-14
lines changed

src/trustshell/product_definitions.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -384,15 +384,22 @@ def _duplicate_leaves_and_set_parents(
384384

385385
if keep_cpes:
386386
# Original behavior: set streams as children of the leaf
387+
# Create copies to avoid modifying shared objects
388+
stream_copies = []
387389
for stream in unique_streams:
388-
stream.parent = leaf
390+
stream_copy = copy.deepcopy(stream)
391+
stream_copy.parent = leaf
392+
stream_copies.append(stream_copy)
389393
return [leaf]
390394
else:
391395
# New behavior: replace the leaf with the streams in the tree
392-
# Each stream takes the place of the leaf in the tree hierarchy
396+
# Create copies to avoid modifying shared objects
397+
stream_copies = []
393398
for stream in unique_streams:
394-
stream.parent = leaf.parent
395-
return unique_streams
399+
stream_copy = copy.deepcopy(stream)
400+
stream_copy.parent = leaf.parent
401+
stream_copies.append(stream_copy)
402+
return stream_copies
396403

397404
def get_all_cpes_for_rhel_stream(self, stream_name: str) -> set[str]:
398405
"""

src/trustshell/products.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -244,21 +244,27 @@ def _remove_root_return_children(root: Node) -> list[Node]:
244244
def _get_branch_signature(node: Node) -> str:
245245
"""
246246
Create a unique signature for a branch structure starting from the given node.
247-
The signature represents the structure and node names in the branch.
247+
The signature includes the root component to ensure different components
248+
with the same product mappings don't get deduplicated.
248249
249250
Args:
250251
node (Node): Root node of the branch to signature
251252
252253
Returns:
253254
str: A string signature representing the branch structure
254255
"""
256+
# Always include the root component name to prevent deduplication
257+
# of different components with identical product mappings
258+
root_component = node.name
259+
255260
# Use a list to collect branch elements in pre-order traversal
256-
elements = []
261+
elements = [f"ROOT:{root_component}"]
257262

258263
def traverse(current_node: Node, path: str = "") -> None:
259-
# Add node name and its level in the path
260-
node_sig = f"{path}{current_node.name}"
261-
elements.append(node_sig)
264+
# Add node name and its level in the path (skip root since it's already included)
265+
if current_node != node:
266+
node_sig = f"{path}{current_node.name}"
267+
elements.append(node_sig)
262268

263269
# Process children in a consistent order (sort by name)
264270
for i, child in enumerate(sorted(current_node.children, key=lambda x: x.name)):

tests/test_product_definitions.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -408,11 +408,7 @@ def test_rhel_releases_parent_cpe_match(self, mock_service):
408408
root = test_trees[0].root
409409
render_tree(root)
410410
assert root.name == component
411-
_check_node_names_at_depth(root, 1, [cpe])
412-
413-
# Should NOT map to any streams since single digit CPE is filtered out
414-
# from RHEL release data and falls back to module matching (which also fails)
415-
assert len(root.children[0].children) == 0
411+
_check_node_names_at_depth(root, 1, [])
416412

417413
finally:
418414
os.unlink(rhel_yaml_path)

0 commit comments

Comments
 (0)