Skip to content

Conversation

@tysonclugg
Copy link

Description

Use PEP 3134 (https://peps.python.org/pep-3134/) exception chaining to provide enhanced reporting and extra context when errors are encountered.

This was primarily so I could debug issues while developing my own nested serializers that were failing validation. I wanted to see the specifics of how the validation had failed, chaining the exceptions raised along with adding the following to my settings.py proved to be very helpful:

def raise_api_exception(exc, context):
    raise exc

REST_FRAMEWORK = {
    "EXCEPTION_HANDLER": f"{__name__}.raise_api_exception",
}

Use PEP 3134 (https://peps.python.org/pep-3134/) exception chaining to
provide enhanced reporting and extra context when errors are encountered.
@carltongibson
Copy link
Collaborator

Ref #7378. As per the PEP, exceptions are automatically chained regardless of use of the from keyword, which serves to allow specifying the specific cause, for example if wanting to highlight an exception deeper in the stack. I don't see any benefit to adding it throughout the code base. (Indeed the extra verbosity reverse.)

@carltongibson
Copy link
Collaborator

Closing on the basis of the previous discussion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants