Opened 13 years ago
Closed 13 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 |
Description
The file session backend does not work at all in Windows. The culprit is this code in django.contrib.sessions.backends.file.SessionStore.save():
try:
try:
os.write(output_file_fd, self.encode(session_data).encode())
finally:
os.close(output_file_fd)
os.rename(output_file_name, session_file_name)
renamed = True
finally:
if not renamed:
os.unlink(output_file_name)
The os.rename call cannot be used to replace a file directly in Windows ( http://docs.python.org/2/library/os.html#os.rename ). 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\utils.py", line 220, in inner
return test_func(*args, **kwargs)
File "C:\[...]\site-packages\django\contrib\sessions\tests.py", 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).
Duplicate of #9084, fixed in master.