Skip to content

Commit 74e9e5e

Browse files
authored
Fix a bug with the scan_status_fields on empty runs (#433)
Signed-off-by: tdruez <[email protected]>
1 parent c8f5a3f commit 74e9e5e

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

component_catalog/views.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
from django.contrib.auth.mixins import LoginRequiredMixin
2020
from django.core import signing
2121
from django.core.validators import EMPTY_VALUES
22+
from django.db import transaction
2223
from django.db.models import Count
2324
from django.db.models import Prefetch
2425
from django.http import FileResponse
@@ -1530,6 +1531,15 @@ def get_scan_progress_htmx_view(request, dataspace, uuid):
15301531
return render(request, template, context)
15311532

15321533

1534+
# Non-atomic mode ensures Package instances are committed to the database immediately
1535+
# rather than being held in a transaction. This is critical when DEJACODE_ASYNC=False
1536+
# (eager/synchronous mode), where the `send_scan_notification` callback from
1537+
# ScanCode.io executes synchronously and must be able to query the newly created
1538+
# Packages from the database.
1539+
# Note: Using `transaction.on_commit()` would delay all scans until the entire
1540+
# package set is created, whereas this approach starts scans immediately for faster
1541+
# results.
1542+
@transaction.non_atomic_requests
15331543
@login_required
15341544
@require_POST
15351545
def package_create_ajax_view(request):
@@ -2394,7 +2404,8 @@ def scan_summary_fields(self, scan_summary):
23942404
def scan_status_fields(self, scan):
23952405
package = self.object
23962406
scan_status_fields = []
2397-
scan_run = scan.get("runs", [{}])[-1]
2407+
scan_runs = scan.get("runs", None) or [{}]
2408+
scan_run = scan_runs[-1]
23982409
status = scan_run.get("status")
23992410
scan_uuid = scan.get("uuid")
24002411

dejacode_toolkit/scancodeio.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ def refresh_scan(self, project_uuid):
163163
logger.debug(f"{self.label}: refresh scan reset_url={reset_url}")
164164
data = {
165165
"keep_input": True,
166+
"keep_webhook": True,
166167
"restore_pipelines": True,
167168
"execute_now": True,
168169
}

0 commit comments

Comments
 (0)