Re: [Django] #9084: [BUG] file-based session does not store any data on Windows

2008-09-16 Thread Django
#9084: [BUG] file-based session does not store any data on Windows
--+-
  Reporter:  mizutori | Owner:  mtredinnick
Status:  assigned | Milestone:  post-1.0   
 Component:  django.contrib.sessions  |   Version:  1.0
Resolution:   |  Keywords: 
 Stage:  Accepted | Has_patch:  0  
Needs_docs:  0|   Needs_tests:  0  
Needs_better_patch:  0|  
--+-
Changes (by mtredinnick):

  * status:  new => assigned
  * needs_better_patch:  => 0
  * needs_tests:  => 0
  * owner:  nobody => mtredinnick
  * needs_docs:  => 0
  * stage:  Unreviewed => Accepted

Comment:

 Whoops. Yes, you're right. `os.rename()` does need a clear landing zone on
 Windows. There's been talk from time to time of creating `atomic_rename`
 or something similar in Python that is cross-platform, but it doesn't
 exist yet.

-- 
Ticket URL: 
Django 
The Web framework for perfectionists with deadlines.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to django-updates@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en
-~--~~~~--~~--~--~---



[Django] #9084: [BUG] file-based session does not store any data on Windows

2008-09-15 Thread Django
#9084: [BUG] file-based session does not store any data on Windows
-+--
 Reporter:  mizutori |   Owner:  nobody
   Status:  new  |   Milestone:  post-1.0  
Component:  django.contrib.sessions  | Version:  1.0   
 Keywords:   |   Stage:  Unreviewed
Has_patch:  0|  
-+--
 Django 1.0 (or trunk r9029) has a bug that does not store any session data
 using file-based sessions on Windows system.
 [[BR]]
 [[BR]]
 [1] Sample code[[BR]]

 To use file-based sessions, set the SESSION_ENGINE setting to
 "django.contrib.sessions.backends.file". On Windows system, the following
 code does not work properly. The session data for "sess_key" will never be
 passed to the next index2 session.

 {{{
 ---[ views.py ]---
 def index(request):
 request.session['sess_key'] = "yes"
 request.session.modified = True
 return HttpResponseRedirect('index2.html')

 def index2(request):
 print "session key="+repr(request.session['sess_key'])
 return HttpResponseRedirect('index3.html')
 ---
 }}}

 [2] My analysis[[BR]]

 This is a bug of save() function of
 django.contrib.sessions.backends.file.SessionStore class. On Windows,
 os.rename function of Python will raise OSError if the destination file
 already exists. Whereas on Unix, it will be removed silently. To fix this
 problem, remove the existing file before renaming if the current operating
 system is Windows.
 [[BR]]
 [[BR]]
 [3] My workaround[[BR]]

 Apply unlink() function before rename() if the operating system is Windows
 to fix the save() function of file.SessionStore class.

 {{{
 ---[ django/contrib/sessions/backends/file.py ]---
 def save(self, must_create=False):
 ...
 try:
 ...
 #00122:
 +   if os.name == "nt":
 +   os.unlink(session_file_name)
 os.rename(output_file_name, session_file_name)
 renamed = True
 ---
 # added patch code with "+" mark
 }}}

-- 
Ticket URL: 
Django 
The Web framework for perfectionists with deadlines.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to django-updates@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en
-~--~~~~--~~--~--~---