Opened 7 years ago

Closed 7 years ago

#5507 closed (fixed)

File bases session backend failing on Win32

Reported by: dougn Owned by: PhiR
Component: Contrib apps Version: master
Severity: Keywords: sessions, file backend
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

The new file based Session backend (ticket #2066, changeset [6333]) fails on Win23 due to the SESSION_FILE_PATH defaulting to '/tmp/'

django/trunk/django/conf/global_settings.py should get the default using the environ for the temporary storage on Win32/OSX

Adding the following to your local test settings file will work as a temporary workaround:

SESSION_FILE_PATH = os.environ['TMP']

Test Failure:

======================================================================
FAIL: Doctest: django.contrib.sessions.tests
----------------------------------------------------------------------
Traceback (most recent call last):
  File "C:\django-sprint\trunk\django\test\_doctest.py", line 2169, in runTest
    raise self.failureException(self.format_failure(new.getvalue()))
AssertionError: Failed doctest test for django.contrib.sessions.tests
  File "C:\django-sprint\trunk\django\contrib\sessions\tests.py", line 0, in tests

----------------------------------------------------------------------
File "C:\django-sprint\trunk\django\contrib\sessions\tests.py", line 35, in django.contrib.sessions.tests
Failed example:
    file_session.exists(file_session.session_key)
Expected:
    True
Got:
    False


----------------------------------------------------------------------
Ran 165 tests in 291.149s

FAILED (failures=1)

Attachments (2)

5507.diff (1.1 KB) - added by PhiR 7 years ago.
updated for latest revision
5507_simple.diff (2.1 KB) - added by PhiR 7 years ago.
better patch, even has docs!

Download all attachments as: .zip

Change History (13)

comment:1 Changed 7 years ago by Simon G. <dev@…>

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted

comment:2 Changed 7 years ago by PhiR

  • Component changed from Unit test system to Contrib apps
  • Has patch set
  • Owner changed from nobody to PhiR
  • Status changed from new to assigned

attached patch fixes the issue. Tested under windows and linux, but should be portable due to the use of tempfile.gettempdir().

comment:3 Changed 7 years ago by dougn

I fear there might be a meta-bug in here. The failure to create the session file should have resulted in an error, not the test returning 'False' when checking to see if there is a session. The real error (which could be permission based, or even typo based), is lost somewhere. I see this as being the equivalent to not having the table created in teh database, which gives an appropriate backend exception.

comment:4 follow-up: Changed 7 years ago by deadwisdom

Yeah, I agree. In the meanwhile, I suggest commiting this patch asap so that tests can continue to be run on Windows.

comment:5 in reply to: ↑ 4 Changed 7 years ago by allandouglas@…

Replying to deadwisdom:

Yeah, I agree. In the meanwhile, I suggest commiting this patch asap so that tests can continue to be run on Windows.

Please commit it.

Changed 7 years ago by PhiR

updated for latest revision

comment:6 Changed 7 years ago by PhiR

  • Triage Stage changed from Accepted to Ready for checkin

comment:7 Changed 7 years ago by Alex

gettempdir()'s return doesn't have the trailing slash(on linux at least it returns '/tmp') would this be a problem?

comment:8 Changed 7 years ago by mtredinnick

  • Needs documentation set
  • Patch needs improvement set
  • Triage Stage changed from Ready for checkin to Accepted
  1. Imports don't belong in the middle of files. They go at the top.
  2. Instead of importing tempfile unconditionally in settings.py, when it's only needed for the file-based session backend, let's have that setting default to None which will mean "at use time, it will be converted to the tmp directory's location" and then we can pick the right value in django.contrib.session.backends.file. We try fairly hard to avoid importing unneeded modules that are only going to be used rarely and this is one of those cases.

comment:9 Changed 7 years ago by PhiR

  • Patch needs improvement unset

Followed malcolm's guidance.

Alex: no the backend uses os.path.join so it will be added as/if needed.

Changed 7 years ago by PhiR

better patch, even has docs!

comment:10 Changed 7 years ago by PhiR

  • Needs documentation unset
  • Triage Stage changed from Accepted to Ready for checkin

comment:11 Changed 7 years ago by mtredinnick

  • Resolution set to fixed
  • Status changed from assigned to closed

(In [7329]) Fixed #5507 -- Use a more portable way to get at the system's tmpdir (fixes a
problem with the default on Windows). Thanks, Philippe Raoult.

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