#20308 closed Bug (duplicate)

File session backend does not work in Windows

Reported by: mlarente 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).

Attachments (0)

Change History (1)

comment:1 Changed 15 months ago by aaugustin

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

Duplicate of #9084, fixed in master.

Add Comment

Modify Ticket

Change Properties
<Author field>
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'

E-mail address and user name can be saved in the Preferences.

Note: See TracTickets for help on using tickets.