Reload api_settings when using Django's 'override_settings'#2473
Reload api_settings when using Django's 'override_settings'#2473lovelydinosaur merged 1 commit intomasterfrom
Conversation
|
Based on reviewing django code I'm tempted to consider "Only access api_settings inside running code, not inside class declarations." as a possibility. Note potential conflict of that approach with #2470. |
|
My suggestion would be not to complicate things with reloading; since |
|
We could although that wouldn't solve the class attributes that we set, such as APIView.renderer_classes. Those would still be evaluated at module import time. |
|
Tom this PR is very helpful. Going over the four options outlined - ordering them from worst to best in my opinion:
The 'runtime only' solution could probably be phased in over releases, and if there was documentation of the issue in the testing section of the site, this would create space for explaining which settings may not take effect when adjusted with Document now with helper and then work towards to 'runtime only' seems like a nice way to progress to me. |
@jamescooke Sounds sensible to me, yup! Esp the incremental approach. |
Reload api_settings when using Django's 'override_settings'
|
👍 |
|
Is there a way to reload the DEFAULT_AUTHENTICATION_CLASSES and DEFAULT_PERMISSION_CLASSES when the view is defined as function with the @api_view['GET'] decorator? |
Solution is similar to encode/django-rest-framework#2473
Closes #2466, however not yet entirely happy with this.
Note that various REST framework views set class attributes such as...
Effect of this is that if
rest_framework.viewshas been imported then changingapi_settingsisn't enough, asAPIView.renderer_classes(and others) have already been set.The two tests using
override_settingsin this pull request usereload_moduleto ensure that the required REST framework modules are reloaded to get the new settings.Possible approaches to solve:
api_settings.somethingreturns a lazy object. (Or wrap the class declarations)api_settingsinside running code, not inside class declarations.