-
Notifications
You must be signed in to change notification settings - Fork 45
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Handle unauthorized exceptions in a custom handler #1255
Conversation
8080e46
to
431810f
Compare
|
||
REST_FRAMEWORK = settings.REST_FRAMEWORK | ||
REST_FRAMEWORK.update( | ||
{"EXCEPTION_HANDLER": "pulp_container.app.exceptions.unauthorized_exception_handler"} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Won't this set the exception handler for all plugins?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, that is a good question. I think it probably will. 😭
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can try cloning this to make it available only to pulp_container.
431810f
to
1b811cf
Compare
1b811cf
to
7f78491
Compare
from django.conf import settings | ||
|
||
DRF_ACCESS_POLICY = { | ||
"dynaconf_merge_unique": True, | ||
"reusable_conditions": ["pulp_container.app.global_access_conditions"], | ||
} | ||
|
||
REST_FRAMEWORK = deepcopy(settings.REST_FRAMEWORK) | ||
REST_FRAMEWORK.update( | ||
{"EXCEPTION_HANDLER": "pulp_container.app.exceptions.unauthorized_exception_handler"} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
from django.conf import settings | |
DRF_ACCESS_POLICY = { | |
"dynaconf_merge_unique": True, | |
"reusable_conditions": ["pulp_container.app.global_access_conditions"], | |
} | |
REST_FRAMEWORK = deepcopy(settings.REST_FRAMEWORK) | |
REST_FRAMEWORK.update( | |
{"EXCEPTION_HANDLER": "pulp_container.app.exceptions.unauthorized_exception_handler"} | |
DRF_ACCESS_POLICY__reusable_conditions = "@merge_unique pulp_container.app.global_access_conditions" | |
REST_FRAMEWORK__EXCEPTION_HANDLER = "pulp_container.app.exceptions.unauthorized_exception_handler" |
@@ -1,4 +1,12 @@ | |||
from copy import deepcopy | |||
from django.conf import settings |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don' t recommend importing django.conf.settings
here, you can use dynaconf inline merging with @
and __
(as in my other comment)
DRF_ACCESS_POLICY__reusable_conditions = "@merge_unique pulp_container.app.global_access_conditions"
REST_FRAMEWORK__EXCEPTION_HANDLER = "pulp_container.app.exceptions.unauthorized_exception_handler"
Or you can add a pulp_container/app/dynaconf_hooks.py
and then do any conditionals or updates there.
dynaconf_hooks.py
def post(settings):
data = {"dynaconf_merge": True}
data["REST_FRAMEWORK"]["EXCEPTION_HANDLER"] = "..."
return data
The reason is that as settings is formed by the merging of multiple sources the final state is not the one you get grom django.conf at this point here.
I am closing this PR in favour of #1256 |
closes #1254