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
IGNORE_URL setting to opt-out for some URLs #37
Comments
Hmm, I see. I do have the same in my setup, but I don't really look at the logs without filters so haven't really noticed it. I understand where you're coming from, though. As a quickfix right now you could disable that log for all requests by adding For your suggestion I'm pretty sure it's not possible to disable middlewares from a view. (However it is possible to append a middleware before the view by using |
Thank you for the quick and thoughtful response I guess a IGNORE_URLS list would work but I personally like the decorator one better - the list can collect stale URLs as developers will remove urls and forget to update the list. The CSRF protection middleware has a I can change your middleware to use the The only negative impact that maybe can happen is a change in the position of your middleware's logic (in relation to the other middlewares). And I would like your permission before I even invest time in checking this - assuming no impact on the middlewares order, the only impact would be less elegant code - would it be ok to move the middleware handling (or some of it) from |
I see, thanks for doing the research! If your assumption turns out to be right and the only impact would be less elegant code I'm not against the idea at all, however it's important to me that there's either good comments or docs that explains it. I want people to understand what's happening and why, making it easy to extend, contribute to and most importantly learn from. |
hi, So I did a quick test now - I added a middleware before and after the Guid middleware with logs in their Unfortunately, the order of the calls is:
So, if the GUID is added today at step 2 - and is visible in the logs of steps 3+ but if I move it to process_view (so that I can opt-out by checking the view-function), the GUID will be added at step 5. I sadly recommend to give up on an opt-out decorator, and maybe revisit this in Django 4.0 if they change the way middleware work. I'll make a PR with an (optional) IGNORE_URLS setting, as you suggested. |
I understand. Thanks for testing it out and reporting back! |
I have a few requests that I don't want to see in the logs
eg. a load balancer sends a "ping" once in a while to see the server is up
the logs are spammed with generated new GUID messages:
for this request I would prefer to opt out of the middleware - a decorator would work nicely
Edit:
It turns out that to use a decorator for opt-out would require to use the process_view hook, which runs after all the middelwares
__call__
methods have been run. If the GUID would only be added at that point, it wouldn't be useful for debugging of other middleware, which is not a good idea.For that reason, instead of a decorator, the plan is to use a "black list" of URLs to ignore. I edited the Issue title to reflect this change.
The text was updated successfully, but these errors were encountered: