From ca8f0cee9f5009e0f28a4b9a46924cdbdcac65a0 Mon Sep 17 00:00:00 2001 From: Oliver Date: Mon, 18 Mar 2024 21:28:04 +1100 Subject: [PATCH] Error handling fix (#6741) * Handle case where error message is *not* a dict * Encode as list --- InvenTree/InvenTree/serializers.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/InvenTree/InvenTree/serializers.py b/InvenTree/InvenTree/serializers.py index 4745647ea5..3b4978d15d 100644 --- a/InvenTree/InvenTree/serializers.py +++ b/InvenTree/InvenTree/serializers.py @@ -352,7 +352,12 @@ class InvenTreeModelSerializer(serializers.ModelSerializer): try: instance.full_clean() except (ValidationError, DjangoValidationError) as exc: - data = exc.message_dict + if hasattr(exc, 'message_dict'): + data = exc.message_dict + elif hasattr(exc, 'message'): + data = {'non_field_errors': [str(exc.message)]} + else: + data = {'non_field_errors': [str(exc)]} # Change '__all__' key (django style) to 'non_field_errors' (DRF style) if '__all__' in data: