question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

AttributeError: 'WSGIRequest' object has no attribute 'tenant'

See original GitHub issue

I get this error when I use subfolder middleware Traceback (most recent call last): File "/home/vypa/projects/together_app_backend/together_backend/env/lib/python3.8/site-packages/django/core/handlers/exception.py", line 47, in inner response = get_response(request) File "/home/vypa/projects/together_app_backend/together_backend/env/lib/python3.8/site-packages/django/utils/deprecation.py", line 116, in __call__ response = self.process_request(request) File "/home/vypa/projects/together_app_backend/together_backend/env/lib/python3.8/site-packages/django_tenants/middleware/subfolder.py", line 55, in process_request self.setup_url_routing(request) File "/home/vypa/projects/together_app_backend/together_backend/env/lib/python3.8/site-packages/django_tenants/middleware/main.py", line 79, in setup_url_routing (force_public or request.tenant.schema_name == get_public_schema_name())): AttributeError: 'WSGIRequest' object has no attribute 'tenant'

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:1
  • Comments:10 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
pprolancercommented, Jul 19, 2021

Hi @gerald9784

Seems this is a bug in subroute feature. I have fixed that by extending the TenantSubfolderMiddleware and overrided the “setup_url_routing” function. something like this:

from django.conf import settings
from django_tenants.middleware import TenantSubfolderMiddleware
from django_tenants.utils import get_public_schema_name, has_multi_type_tenants

class CustomTenantSubfolderMiddleware(TenantSubfolderMiddleware):

    @staticmethod
    def setup_url_routing(request, force_public=False):
        """
        Sets the correct url conf based on the tenant
        :param request:
        :param force_public
        """
        public_schema_name = get_public_schema_name()
        if has_multi_type_tenants():
            return TenantSubfolderMiddleware.setup_url_routing(request, force_public=force_public)

        # Do we have a public-specific urlconf?
        if (hasattr(settings, 'PUBLIC_SCHEMA_URLCONF') and
                (force_public or (not hasattr(request, 'tenant')) or
                 request.tenant.schema_name == get_public_schema_name())):
            request.urlconf = settings.PUBLIC_SCHEMA_URLCONF

and finally in your setting replace the django_tenant middleware with this new CustomTenantSubfolderMiddleware class: OLD:

MIDDLEWARE = [
    'django_tenants.middleware.TenantSubfolderMiddleware',
    ...
]

NEW:

MIDDLEWARE = [
    'your_project.middleware.CustomTenantSubfolderMiddleware',
    ...
]

I hope this help you!

0reactions
cclausscommented, Aug 15, 2022

Was this issue fixed by #642? If not, could this issue be related to the version of gunicorn?

Read more comments on GitHub >

github_iconTop Results From Across the Web

'WSGIRequest' object has no attribute 'user' - Stack Overflow
I'am trying to make an auth module in my django project. But when I open my web site url I have a this...
Read more >
Shouldn't TenantRequestFactory request have `.tenant ...
rf = TenantRequestFactory(self.tenant) request = rf.post('/') ... AttributeError: 'WSGIRequest' object has no attribute 'tenant'.
Read more >
WSGIRequest' object has no attribute 'get' error after submitting
I have the following codes: models.py class Job(models.Model): datetime = models.DateTimeField(default=timezone.now) associateddevice ...
Read more >
'WSGIRequest' object has no attribute 'update' - Google Groups
'WSGIRequest' object has no attribute 'update' ... Hi all..i am learning django no, using django 1.3 + python 2.7 . i came from...
Read more >
AttributeError: 'WSGIRequest' object has no attribute 'user'
[stage][traceback] 500 Error: AttributeError: 'WSGIRequest' object has no attribute 'user'.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found