mbr / flask-kvsession

A drop-in replacement for Flask's session handling using server-side sessions.
http://pythonhosted.org/Flask-KVSession/
MIT License
168 stars 53 forks source link

`session.regenerate()` raises an error if called on the first request #10

Closed ereOn closed 11 years ago

ereOn commented 12 years ago

I recently faced the following error:

AttributeError: 'KVSession' object has no attribute 'sid_s'

When calling session.regenerate() in my flask project. I guess this issue is very similar to this one.

This happens when session.regenerate() is called on the first request. Whether it is a GET or POST doesn't matter, and the aforementioned error is raised.

Adding:

if not hasattr(session, 'sid_s'):
  session.sid_s = None

Before the call fixes the issues, but is hardly a long-term and clean solution.

I understood the rationale of raising an error when the programmer makes a mistake, however it doesn't seem like calling regenerate() on a first request is a mistake. Or is it ?

I see no way of checking whether a session exists so its quite hard to avoid.

mbr commented 12 years ago

This is a somewhat tricky bug to test, as I haven't been able to create a TestCase reproducing it (a standalone app worked fine though). If you have some spare time, please checkout the latest master branch and see if that fixes your problem. I've written a minimal app to reproduce the bug in regenerate_on_first_request.py as well.

ereOn commented 12 years ago

I could indeed reproduce the bug with my current installed version (not master), with your regenerate_on_first_request.py sample and with the following shell command :

curl http://localhost:5000

With the master branch including your fix, the bug doesn't occur anymore.

Do you have any idea when you intend to release that fixed version ?

Anyway, thank you for your fix and congratulations for your work. This library is a nice piece of code.

mbr commented 12 years ago

Thanks.

I just released 0.3.2 on PyPI - you could do me a big favor by checking if everything works okay.

ereOn commented 12 years ago

Works on my side with the 0.3.2 version.

Thank you very much.