🐛(back) fix ValidationError exception handler

The exception handler for the ValidationError was not testing correctly
the existence of some attributes like `message_dict`.
This commit is contained in:
Manuel Raynaud
2025-03-06 14:46:46 +01:00
parent 5bb7ad643a
commit 38eb6d45b7
2 changed files with 11 additions and 7 deletions

View File

@@ -17,9 +17,10 @@ def exception_handler(exc, context):
https://gist.github.com/twidi/9d55486c36b6a51bdcb05ce3a763e79f https://gist.github.com/twidi/9d55486c36b6a51bdcb05ce3a763e79f
""" """
if isinstance(exc, ValidationError): if isinstance(exc, ValidationError):
detail = exc.message_dict detail = None
if hasattr(exc, "message_dict"):
if hasattr(exc, "message"): detail = exc.message_dict
elif hasattr(exc, "message"):
detail = exc.message detail = exc.message
elif hasattr(exc, "messages"): elif hasattr(exc, "messages"):
detail = exc.messages detail = exc.messages

View File

@@ -424,7 +424,8 @@ def test_api_document_invitations_create_privileged_members(
def test_api_document_invitations_create_email_from_senders_language(): def test_api_document_invitations_create_email_from_senders_language():
""" """
When inviting on a document a user who does not exist yet in our database, the invitation email should be sent in the language of the sending user. When inviting on a document a user who does not exist yet in our database,
the invitation email should be sent in the language of the sending user.
""" """
user = factories.UserFactory(language="fr-fr") user = factories.UserFactory(language="fr-fr")
document = factories.DocumentFactory() document = factories.DocumentFactory()
@@ -559,9 +560,11 @@ def test_api_document_invitations_create_cannot_duplicate_invitation():
) )
assert response.status_code == 400 assert response.status_code == 400
assert response.json() == [ assert response.json() == {
"Document invitation with this Email address and Document already exists." "__all__": [
] "Document invitation with this Email address and Document already exists."
],
}
def test_api_document_invitations_create_cannot_invite_existing_users(): def test_api_document_invitations_create_cannot_invite_existing_users():