From dbf2bd5abab0229d4b84c195574245aeaae03db1 Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Wed, 1 Feb 2023 19:45:36 +0100 Subject: [PATCH] blueprints: handle error when blueprint entry identifier field does not exist closes #4588 Signed-off-by: Jens Langhammer --- authentik/blueprints/v1/importer.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/authentik/blueprints/v1/importer.py b/authentik/blueprints/v1/importer.py index 6b32559ba..1ee14287a 100644 --- a/authentik/blueprints/v1/importer.py +++ b/authentik/blueprints/v1/importer.py @@ -7,6 +7,7 @@ from dacite.config import Config from dacite.core import from_dict from dacite.exceptions import DaciteError from deepmerge import always_merger +from django.core.exceptions import FieldError from django.db import transaction from django.db.models import Model from django.db.models.query_utils import Q @@ -181,7 +182,10 @@ class Importer: if not query: raise EntryInvalidError("No or invalid identifiers") - existing_models = model.objects.filter(query) + try: + existing_models = model.objects.filter(query) + except FieldError as exc: + raise EntryInvalidError(f"Invalid identifier field: {exc}") from exc serializer_kwargs = {} model_instance = existing_models.first()