Opened 5 years ago

Closed 5 years ago

#20308 closed Bug (duplicate)

File session backend does not work in Windows

Reported by: Martin Larente Owned by: nobody
Component: contrib.sessions Version: 1.5
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


The file session backend does not work at all in Windows. The culprit is this code in

            os.write(output_file_fd, self.encode(session_data).encode())
        os.rename(output_file_name, session_file_name)
        renamed = True
        if not renamed:

The os.rename call cannot be used to replace a file directly in Windows ( ). The result is that the files saved by the backends are always empty.

I understand that Windows file handling might not be suited to use the file session backend. However, what's annoying is that it makes a test fail as well, even if I don't use the backend:

FAIL: test_clearsessions_command (django.contrib.sessions.tests.FileSessionTests)
Traceback (most recent call last):
  File "C:\[...]\site-packages\django\test\", line 220, in inner
    return test_func(*args, **kwargs)
  File "C:\[...]\site-packages\django\contrib\sessions\", line 444, in test_clearsessions_command
    self.assertEqual(1, count_sessions())
AssertionError: 1 != 2

I think this bug should either be fixed or the test be changed to be skipped in Windows (and the documentation should also mention that the file backend cannot be used in Windows).

Change History (1)

comment:1 Changed 5 years ago by Aymeric Augustin

Resolution: duplicate
Status: newclosed

Duplicate of #9084, fixed in master.

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