-
Notifications
You must be signed in to change notification settings - Fork 553
feat(django): Pick custom urlconf up from request if any #1308
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
Conversation
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.
Looks nice. I have just one question.
|
||
content, status, _headers = client.get("/custom/ok") | ||
assert status.lower() == "200 ok" | ||
assert b"".join(content) == b"custom ok" |
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.
why do we need the bytes literal here?
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.
it's a byte stream or something from werkzeug
, not a string. I just followed the other tests.
Premise
Django middlewares sometimes can override
request.urlconf
for the current request which it has a contract for using subsequently as the source of truth for url related operations.As a result, we also need to respect the overwritten
urlconf
in our transaction name resolving.Solution
I finally went with an
_after_get_response
solution. The resolution is repeated code but runs only ifurlconf
is overwritten. I wanted to touch as little of existing logic as possible.For reference, I went back and forth several times between doing it in a couple of other places.
_before_get_response
- this doesn't work because it runs before all the django middlewaresProblem
One of our customers have a
django-tenants
multi-tenant setup. They have a dynamically resolvedurlconf
and setROOT_URLCONF
to an empty string which breaks thisget_resolver
in Django.This results in a silent exception when we try to update the transaction name and hence they see
Generic WSGI request
for all their requests.References