You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Serialization of nested Components with Dependencies drops transitive dependencies #328
I am not sure if this is a bug or just a misunderstanding how Component nesting and Dependencies interact.
I have a nested BOM with multiple components that also declare dependencies between each other along the nesting hierarchy, like in the code below. An example of such a structure would be some framework with multiple applications that have dependencies on a bunch of 3rd party libraries.
fromcyclonedx.model.bomimportBomfromcyclonedx.model.componentimportComponentfromcyclonedx.outputimportget_instance, OutputFormat, SchemaVersionbom=Bom()
a=Component(name='A', version='0.1')
b=Component(name='B', version='1.0')
c=Component(name='C', version='1.0')
# Make a tree of components A -> B -> Cb.components= [c]
a.components= [b]
# Declare dependencies the same wayb.dependencies= [c.bom_ref]
a.dependencies= [b.bom_ref]
bom.components= [a]
inst=get_instance(
bom=bom,
output_format=OutputFormat["XML"],
schema_version=SchemaVersion["V1_4"],
)
inst.output_to_file("bom.xml")
This results in the following XML output (for components and dependencies):
The dependency of B on C is dropped in the serialization.
I would have expected the serialization to preserve the dependencies of the nested components as well.
I remember we had this bug before, and it was supposed to be fixed.
Will check if we have a regression test for it. If not, I will create one.
Will check if this is reproducible and fixable.
Confirmed that this is also resolved in 4.0.0 branch, but given breaking changes, would be written as:
from cyclonedx.model.bom import Bom
from cyclonedx.model.component import Component
from cyclonedx.output import get_instance, OutputFormat, SchemaVersion
bom = Bom()
a = Component(name='A', version='0.1')
b = Component(name='B', version='1.0')
c = Component(name='C', version='1.0')
# Make a tree of components A -> B -> C
b.components = [c]
a.components = [b]
# Declare dependencies the same way
bom.register_dependency(b, [c])
bom.register_dependency(a, [b])
bom.components = [a]
inst = get_instance(
bom=bom,
output_format=OutputFormat["XML"],
schema_version=SchemaVersion["V1_4"],
)
inst.output_to_file("bom.xml")
Activity
schlenk commentedon Jan 4, 2023
Looking at the dependency graph example at: https://cyclonedx.org/use-cases/#dependency-graph i would expect a flattend 1 node deep serialization like this:
The reason is probably that
cyclonedx-python-lib/cyclonedx/output/xml.py
Line 114 in 539b57a
jkowalleck commentedon Jan 6, 2023
I remember we had this bug before, and it was supposed to be fixed.
Will check if we have a regression test for it. If not, I will create one.
Will check if this is reproducible and fixable.
tests: regression tests for issue #328
tests: regression tests for issue #328
tests: regression tests for issue #328
tests: regression tests for issue #328
tests: regression tests for issue #328
jkowalleck commentedon Jan 6, 2023
tested, confirmed.
having a fix in the making.
tests: regression tests for issue #328
fix: serialize dependency graph for nested components (#329)
madpah commentedon Mar 3, 2023
Confirmed that this is also resolved in
4.0.0branch, but given breaking changes, would be written as:Resulting in dependencies: