I have a baffling problem: my DRF settings are not being taken into account.
In my settings.py, I have:
REST_FRAMEWORK = {"EXCEPTION_HANDLER": "api.exceptions.custom_exception_handler"}
^ This is simplified; I have a few other settings in this dict and they are all getting ignored unless I manually reload the settings. I have confirmed this by dropping into a debugger:
In [1]: from rest_framework.settings import api_settings
In [2]: api_settings.EXCEPTION_HANDLER
Out[2]: <function rest_framework.views.exception_handler(exc, context)>
In [3]: api_settings.reload()
In [4]: api_settings.EXCEPTION_HANDLER
Out[4]: <function api.exceptions.custom_exception_handler(exc, context)>
Everything works as expected if I modify
this line in the DRF source code, replacing:
if not hasattr(self, "_user_settings"):
with
if not hasattr(self, "_user_settings") or not self._user_settings:
It seems like my DRF settings are getting initialized before my django settings have a REST_FRAMEWORK attribute, and are therefore getting set to an empty dict...?
I am using Django 2.2.4 and DRF 3.10.3. (It was also happening into 3.10.2.)
This is driving me crazy, any help would be much appreciated.