Opened 16 years ago

Closed 16 years ago

Last modified 13 years ago

#8457 closed (fixed)

typo in sessions file backend can cause NameError

Reported by: Carl Meyer Owned by: nobody
Component: Uncategorized Version: dev
Severity: Keywords:
Cc: Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

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 (1)

sessions-file-typo.diff (543 bytes ) - added by Carl Meyer 16 years ago.
fix typo in contrib/sessions/file.py

Download all attachments as: .zip

Change History (6)

by Carl Meyer, 16 years ago

Attachment: sessions-file-typo.diff added

fix typo in contrib/sessions/file.py

comment:1 by Malcolm Tredinnick, 16 years ago

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.

comment:2 by Carl Meyer, 16 years ago

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.

comment:3 by Carl Meyer, 16 years ago

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

comment:4 by Malcolm Tredinnick, 16 years ago

Resolution: fixed
Status: newclosed

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

comment:5 by Jacob, 13 years ago

milestone: 1.0

Milestone 1.0 deleted

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