Skip to content

Commit 86b7f93

Browse files
fix: atomic matching on new container
1 parent 65bfa3e commit 86b7f93

2 files changed

Lines changed: 27 additions & 27 deletions

File tree

src/shared/listeners/automatic_linkage.py

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -265,35 +265,36 @@ def build_new_links(container: Container) -> bool:
265265

266266
outcome = resolve_linkage_candidates(container)
267267

268-
proposal = CVEDerivationClusterProposal.objects.create(
269-
cve=container.cve,
270-
status=(
271-
CVEDerivationClusterProposal.Status.REJECTED
268+
with transaction.atomic():
269+
proposal = CVEDerivationClusterProposal.objects.create(
270+
cve=container.cve,
271+
status=(
272+
CVEDerivationClusterProposal.Status.REJECTED
273+
if outcome.rejection
274+
else CVEDerivationClusterProposal.Status.PENDING
275+
),
276+
rejection_reason=outcome.rejection.reason if outcome.rejection else None,
277+
rejection_match_count=outcome.rejection.match_count or None
272278
if outcome.rejection
273-
else CVEDerivationClusterProposal.Status.PENDING
274-
),
275-
rejection_reason=outcome.rejection.reason if outcome.rejection else None,
276-
rejection_match_count=outcome.rejection.match_count or None
277-
if outcome.rejection
278-
else None,
279-
rejection_max_matches_limit=outcome.rejection.max_matches_limit or None
280-
if outcome.rejection
281-
else None,
282-
algorithm_version=CVEDerivationClusterProposal.CURRENT_ALGORITHM_VERSION,
283-
)
284-
285-
if outcome.derivations:
286-
links = build_derivation_links(proposal, outcome.derivations)
287-
DerivationClusterProposalLink.objects.bulk_create(links)
288-
pkg_links = build_package_links(proposal, outcome.derivations)
289-
PackageClusterProposalLink.objects.bulk_create(pkg_links)
290-
logger.info(
291-
"Matching suggestion for '%s': %d derivations, %d packages found.",
292-
container.cve,
293-
len(links),
294-
len(pkg_links),
279+
else None,
280+
rejection_max_matches_limit=outcome.rejection.max_matches_limit or None
281+
if outcome.rejection
282+
else None,
283+
algorithm_version=CVEDerivationClusterProposal.CURRENT_ALGORITHM_VERSION,
295284
)
296285

286+
if outcome.derivations:
287+
links = build_derivation_links(proposal, outcome.derivations)
288+
DerivationClusterProposalLink.objects.bulk_create(links)
289+
pkg_links = build_package_links(proposal, outcome.derivations)
290+
PackageClusterProposalLink.objects.bulk_create(pkg_links)
291+
logger.info(
292+
"Matching suggestion for '%s': %d derivations, %d packages found.",
293+
container.cve,
294+
len(links),
295+
len(pkg_links),
296+
)
297+
297298
return True
298299

299300

src/shared/tests/test_linkage.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -552,7 +552,6 @@ def test_package_link_provenance_flags_merged_across_drvs(
552552
)
553553

554554

555-
@pytest.mark.xfail(reason="Not implemented", strict=True)
556555
def test_build_new_links_is_atomic(
557556
make_container: Callable[..., Container],
558557
make_drv: Callable[..., NixDerivation],

0 commit comments

Comments
 (0)