diff options
| author | Étienne Loks <etienne.loks@iggdrasil.net> | 2025-09-09 14:14:14 +0200 | 
|---|---|---|
| committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2025-10-24 18:32:22 +0200 | 
| commit | 6be52dfe0ec26d2dae593bb7361f31f15d99e7ba (patch) | |
| tree | 8563b4a6e43e84d61c26a3a651f589201176b307 | |
| parent | b2dac51bcd75ce293e928a7d774abb0a3d4d6277 (diff) | |
| download | Ishtar-6be52dfe0ec26d2dae593bb7361f31f15d99e7ba.tar.bz2 Ishtar-6be52dfe0ec26d2dae593bb7361f31f15d99e7ba.zip  | |
🐛 GIS API: do not crash on bad importer configuration
| -rw-r--r-- | ishtar_common/views_api.py | 25 | 
1 files 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):  | 
