You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
While deploying .com we found that SubdomainMiddleware doesn't check the existence of the project that it's injecting at request.slug.
So, any middleware that relies on this to do some extra work, will probably do something like Project.objects.get(slug=request.slug) and will fail.
We workarounded it by adding try/except block in the middleware that uses this, but we should probably just raise a 404 inside the SubdomainMiddleware itself instead of continue with the flow.
@humitos I would like to take this issue up.
If I'm not wrong, you probably want something like this
# Checking if the project exist or notfromdjango.shortcutsimportget_object_or_404get_object_or_404(Project, slug=subdomain)
request.subdomain=Truerequest.slug=subdomainrequest.urlconf=SUBDOMAIN_URLCONFreturnNone
With get_object_or_404, it will show error and does not go further.
@dojutsu-user since this is a code that it's executed a lot, retrieving the whole Project object it may be overkilling since we not going to use that data anyway. You may just need to check if the project does exist with .exists() and using an if in this case.
While deploying .com we found that
SubdomainMiddleware
doesn't check the existence of the project that it's injecting atrequest.slug
.So, any middleware that relies on this to do some extra work, will probably do something like
Project.objects.get(slug=request.slug)
and will fail.We workarounded it by adding
try/except
block in the middleware that uses this, but we should probably just raise a 404 inside theSubdomainMiddleware
itself instead of continue with the flow.Code: https://github.com/rtfd/readthedocs.org/blob/74bbb3ac23b6b06a70517bc1b301961db6821e32/readthedocs/core/middleware.py#L72
The text was updated successfully, but these errors were encountered: