Opened 4 years ago

Closed 4 years ago

#17342 closed Bug (duplicate)

Accessing session in middleware causes contrib.auth tests to fail

Reported by: oinopion Owned by: nobody
Component: contrib.auth Version: master
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

I have custom middleware that looks like this:

class MyMiddleware:
    def process_request(self, request):
        if request.user.is_authenticated():
            pass # not important

After adding to MIDDLEWARE_CLASSES this causes following error to appear in tests:

FAIL: test_session_not_accessed (django.contrib.auth.tests.context_processors.AuthContextProcessorTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/oinopion/Devel/django/django/contrib/auth/tests/context_processors.py", line 31, in test_session_not_accessed
    self.assertContains(response, "Session not accessed")
  File "/home/oinopion/Devel/django/django/test/testcases.py", line 524, in assertContains
    msg_prefix + "Couldn't find '%s' in response" % text)
AssertionError: False is not True : Couldn't find 'Session not accessed' in response

Change History (1)

comment:1 Changed 4 years ago by aaugustin

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Resolution set to duplicate
  • Status changed from new to closed

This was reported in #16366.

Note: See TracTickets for help on using tickets.
Back to Top