From b5bad3b09f538f11fb57180165539ac87ac82224 Mon Sep 17 00:00:00 2001 From: Aditya kumar singh <143548997+Adityakk9031@users.noreply.github.com> Date: Mon, 29 Dec 2025 16:09:40 +0530 Subject: [PATCH] Fix scan_for_virus crash when CodebaseResource is missing Signed-off-by: Aditya kumar singh <143548997+Adityakk9031@users.noreply.github.com> --- scanpipe/pipes/clamav.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/scanpipe/pipes/clamav.py b/scanpipe/pipes/clamav.py index 78a8f45b70..9e4f5a4d40 100644 --- a/scanpipe/pipes/clamav.py +++ b/scanpipe/pipes/clamav.py @@ -23,6 +23,7 @@ from pathlib import Path from django.conf import settings +from django.core.exceptions import ObjectDoesNotExist import clamd @@ -47,7 +48,19 @@ def scan_for_virus(project): status, reason = results resource_path = Path(resource_location).relative_to(project.codebase_path) - resource = project.codebaseresources.get(path=resource_path) + try: + resource = project.codebaseresources.get(path=str(resource_path)) + except ObjectDoesNotExist: + project.add_error( + description="CodebaseResource not found for ClamAV result", + model="ScanForVirus", + details={ + "resource_location": resource_location, + "resource_path": str(resource_path), + }, + ) + continue + virus_report = { "calmav": { "status": status,