Code

Opened 6 years ago

Closed 6 years ago

Last modified 3 years ago

#8457 closed (fixed)

typo in sessions file backend can cause NameError

Reported by: carljm 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:

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 carljm 6 years ago.
fix typo in contrib/sessions/file.py

Download all attachments as: .zip

Change History (6)

Changed 6 years ago by carljm

fix typo in contrib/sessions/file.py

comment:1 Changed 6 years ago by mtredinnick

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

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 6 years ago 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.

comment:3 Changed 6 years ago by carljm

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 6 years ago by mtredinnick

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

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

comment:5 Changed 3 years ago by jacob

  • milestone 1.0 deleted

Milestone 1.0 deleted

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.