|
19 | 19 | from django.contrib.auth.mixins import LoginRequiredMixin |
20 | 20 | from django.core import signing |
21 | 21 | from django.core.validators import EMPTY_VALUES |
| 22 | +from django.db import transaction |
22 | 23 | from django.db.models import Count |
23 | 24 | from django.db.models import Prefetch |
24 | 25 | from django.http import FileResponse |
@@ -1530,6 +1531,15 @@ def get_scan_progress_htmx_view(request, dataspace, uuid): |
1530 | 1531 | return render(request, template, context) |
1531 | 1532 |
|
1532 | 1533 |
|
| 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 |
1533 | 1543 | @login_required |
1534 | 1544 | @require_POST |
1535 | 1545 | def package_create_ajax_view(request): |
@@ -2394,7 +2404,8 @@ def scan_summary_fields(self, scan_summary): |
2394 | 2404 | def scan_status_fields(self, scan): |
2395 | 2405 | package = self.object |
2396 | 2406 | scan_status_fields = [] |
2397 | | - scan_run = scan.get("runs", [{}])[-1] |
| 2407 | + scan_runs = scan.get("runs", None) or [{}] |
| 2408 | + scan_run = scan_runs[-1] |
2398 | 2409 | status = scan_run.get("status") |
2399 | 2410 | scan_uuid = scan.get("uuid") |
2400 | 2411 |
|
|
0 commit comments