Django

Code

Ticket #8457 (closed: fixed)

Opened 3 months ago

Last modified 3 months ago

typo in sessions file backend can cause NameError

Reported by: carljm Assigned to: nobody
Milestone: 1.0 Component: Uncategorized
Version: SVN Keywords:
Cc: Triage Stage: Unreviewed
Has patch: 1 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

Description

In django/contrib/sessions/backends/file.py, SessionStore?.save() refers to "errno.EEXIST" when it means "os.errno.EEXIST". If using the file session backend and set SESSION_FILE_PATH to an unwritable directory (or if there is any other error condition on creating a new session file), this causes a NameError? to be raised instead of the correct OSError. It also prevents the correct handling of the (rare) case of a duplicate session ID being generated. Attached patch fixes the typo.

Attachments

sessions-file-typo.diff (0.5 kB) - added by carljm on 08/20/08 15:26:20.
fix typo in contrib/sessions/file.py

Change History

08/20/08 15:26:20 changed by carljm

  • attachment sessions-file-typo.diff added.

fix typo in contrib/sessions/file.py

08/20/08 15:47:44 changed by mtredinnick

  • needs_better_patch changed.
  • needs_tests changed.
  • needs_docs changed.

This can't be correct. The errno has existed at the top level since of Python, approximately, forever. And os.errno does not exist in normal Python. So you'll need to supply a few more details here about what type of system you're running on and Python you're using, because it sounds very non-standard.

08/20/08 16:03:53 changed by carljm

Sorry, I didn't realize errno was available as a top-level import. The bug still exists, but in that case a just-as-good fix would be to import errno at the top of contrib/sessions/backends/file.py. It currently is not imported and I am definitely able to raise a NameError?. On SVN r8449, set SESSION_FILE_PATH = '/', run "./manage.py shell":

>>> from django.contrib.sessions.backends.file import SessionStore; SessionStore().create()
Traceback (most recent call last):
  File "<console>", line 1, in ?
  File "/var/www/meyer/lib/py/django/contrib/sessions/backends/file.py", line 6e
    self.save(must_create=True)
  File "/var/www/meyer/lib/py/django/contrib/sessions/backends/file.py", line 8e
    if must_create and e.errno == errno.EEXIST:
NameError: global name 'errno' is not defined

My fix also works; os.errno does exist:

carljm@arugula:~$ python
Python 2.5.2 (r252:60911, Jul 31 2008, 17:28:52) 
[GCC 4.2.3 (Ubuntu 4.2.3-2ubuntu7)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> os.errno
<module 'errno' (built-in)>
>>> os.errno.EEXIST
17

There's nothing nonstandard about my setup, Python 2.5.2 straight from the Ubuntu repos.

08/20/08 16:11:18 changed by carljm

Ah, checking on Python 2.4 reveals there's no os.errno there; so clearly importing toplevel errno is the better fix.

08/20/08 16:12:45 changed by mtredinnick

  • status changed from new to closed.
  • resolution set to fixed.

(In [8451]) Fixed #8457 -- Fixed a missing import.


Add/Change #8457 (typo in sessions file backend can cause NameError)




Change Properties
Action