From a903047bdcb765ad2e67cfba1f4b2f9d0bb8efec Mon Sep 17 00:00:00 2001 From: Rajit Sarkar Date: Fri, 1 Mar 2024 10:23:18 -0500 Subject: [PATCH] CONCD-712 previous attempt was not catching the exception, I'm going to just catch all here --- exporter/views.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/exporter/views.py b/exporter/views.py index 67ec51248..ecfffe45d 100644 --- a/exporter/views.py +++ b/exporter/views.py @@ -6,10 +6,10 @@ import bagit import boto3 +from asgiref.sync import sync_to_async from django.conf import settings from django.contrib.admin.views.decorators import staff_member_required from django.contrib.postgres.aggregates.general import StringAgg -from django.core.exceptions import SynchronousOnlyOperation from django.db.models import OuterRef, Subquery from django.http import HttpResponse, HttpResponseRedirect from django.utils.decorators import method_decorator @@ -234,8 +234,12 @@ def get(self, request, *args, **kwargs): return export_to_csv_response( "%s.csv" % self.kwargs["campaign_slug"], headers, data ) - except SynchronousOnlyOperation as e: - logger.info("Failed to export csv, error was: %s", e) + except Exception: + logger.info("Attemping to convert function to async") + export_csv_async = sync_to_async(export_to_csv_response) + return export_csv_async( + "%s.csv" % self.kwargs["campaign_slug"], headers, data + ) class ExportItemToBagIt(TemplateView):