Opened 10 years ago

Closed 10 years ago

Last modified 7 years ago

#8457 closed (fixed)

typo in sessions file backend can cause NameError

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


In django/contrib/sessions/backends/, 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 10 years ago.
fix typo in contrib/sessions/

Download all attachments as: .zip

Change History (6)

Changed 10 years ago by Carl Meyer

Attachment: sessions-file-typo.diff added

fix typo in contrib/sessions/

comment:1 Changed 10 years ago by Malcolm Tredinnick

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 Changed 10 years ago by Carl Meyer

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/ It currently is not imported and I am definitely able to raise a NameError. On SVN r8449, set SESSION_FILE_PATH = '/', run "./ 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/", line 6e
  File "/var/www/meyer/lib/py/django/contrib/sessions/backends/", 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

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

comment:3 Changed 10 years ago by Carl Meyer

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

comment:4 Changed 10 years ago by Malcolm Tredinnick

Resolution: fixed
Status: newclosed

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

comment:5 Changed 7 years ago by Jacob

milestone: 1.0

Milestone 1.0 deleted

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