encode / django-rest-framework

Web APIs for Django. 🎸
https://www.django-rest-framework.org
Other
27.83k stars 6.76k forks source link

Wrap exceptions caused by parsers in ParseError in request wrapper #9453

Open sevdog opened 6 days ago

sevdog commented 6 days ago

Description

To address #9433 (which is caused by https://github.com/python/cpython/issues/90143) simply wraps AttributeErrors which are raised in the parse process into a ParseError.

james-mchugh commented 5 days ago

Looking at request.py, it looks like there is already a precedent for handling this type of error with the wrap_attributeerror context manager defined at https://github.com/encode/django-rest-framework/blob/master/rest_framework/request.py#L68 and then used at

I've opened another PR (#9455) that utilizes this context manager through a safe_property decorator that is utilized by each of the properties in the Request class.