fix: add condition before close the csv file

This commit is contained in:
Adrián Jesús Peña Rodríguez committed 2025-02-12 14:37:01 +01:00
1 parent 747b97fe87
commit f7e27402aa
3 files changed
+9 -2

No files matched your search

+6
View File
@@ -1115,6 +1115,12 @@ class ScanViewSet(BaseRLSViewSet):
def report(self, request, pk=None):
scan_instance = Scan.objects.get(pk=pk)
output_path = scan_instance.output_path
if not output_path:
return Response(
{"detail": "No files found"}, status=status.HTTP_404_NOT_FOUND
)
if scan_instance.upload_to_s3:
s3_client = None
try:
+1 -1
View File
@@ -223,7 +223,7 @@ def generate_outputs(scan_id: str, provider_id: str, tenant_id: str):
)
# Retrieve findings queryset
findings_qs = Finding.objects.filter(scan_id=scan_id)
findings_qs = Finding.objects.filter(scan_id=scan_id).order_by("uid")
# Process findings in batches
for batch, is_last_batch in batched(findings_qs.iterator(), 50):
+2 -1
View File
@@ -102,7 +102,8 @@ class CSV(Output):
csv_writer.writeheader()
for finding in self._data:
csv_writer.writerow(finding)
self._file_descriptor.close()
if self.close_file:
self._file_descriptor.close()
except Exception as error:
logger.error(
f"{error.__class__.__name__}[{error.__traceback__.tb_lineno}]: {error}"