2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-05-01 13:06:45 +00:00

Error handling fix (#6741) (#6744)

* Handle case where error message is *not* a dict

* Encode as list

(cherry picked from commit ca8f0cee9f5009e0f28a4b9a46924cdbdcac65a0)

Co-authored-by: Oliver <oliver.henry.walters@gmail.com>
This commit is contained in:
github-actions[bot] 2024-03-18 23:09:23 +11:00 committed by GitHub
parent beca269e3a
commit f8d6fed06e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -352,7 +352,12 @@ class InvenTreeModelSerializer(serializers.ModelSerializer):
try: try:
instance.full_clean() instance.full_clean()
except (ValidationError, DjangoValidationError) as exc: 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) # Change '__all__' key (django style) to 'non_field_errors' (DRF style)
if '__all__' in data: if '__all__' in data: