From 561853a625afa41ed3941a32b2453af560a90c1a Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Tue, 9 Sep 2025 14:14:14 +0200 Subject: 🐛 GIS API: do not crash on bad importer configuration MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ishtar_common/views_api.py | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/ishtar_common/views_api.py b/ishtar_common/views_api.py index 14cf6b43c..fe301b04d 100644 --- a/ishtar_common/views_api.py +++ b/ishtar_common/views_api.py @@ -26,6 +26,7 @@ from urllib.parse import unquote_plus from rest_framework import serializers, status from rest_framework.response import Response +from ishtar_common.data_importer import ImporterError from ishtar_common.models_common import GeneralType from ishtar_common.models_imports import ImporterType, ImportChunk from ishtar_common.rest import GISAPIView @@ -104,17 +105,21 @@ class GISExportAPI(GISBaseImportView, GISAPIView): dct = {"query": query, "length": self.PAGE_LEN} if page > 1: dct["start"] = (page - 1) * self.PAGE_LEN + 1 + try: + importer_class = importer.get_importer_class() + cols, col_names = importer.get_columns(importer_class=importer_class) + obj_name = importer_class.OBJECT_CLS.__name__.lower() + return get_item(importer_class.OBJECT_CLS, "get_" + obj_name, obj_name, + own_table_cols=cols)( + request, data_type="json", full=False, force_own=False, + no_link=True, col_names=col_names, + col_types=importer.get_columns_types(), + **dct + ) + except ImporterError as e: + return Response({"error": str(e)}, + status=status.HTTP_500_INTERNAL_SERVER_ERROR) - importer_class = importer.get_importer_class() - cols, col_names = importer.get_columns(importer_class=importer_class) - obj_name = importer_class.OBJECT_CLS.__name__.lower() - return get_item(importer_class.OBJECT_CLS, "get_" + obj_name, obj_name, - own_table_cols=cols)( - request, data_type="json", full=False, force_own=False, - no_link=True, col_names=col_names, - col_types=importer.get_columns_types(), - **dct - ) class ImportChunkSerializer(serializers.ModelSerializer): -- cgit v1.2.3