Opened 10 years ago

Closed 10 years ago

#7008 closed (invalid)

Add session backend for Google's App Engine

Reported by: Jannis Leidel Owned by: Jannis Leidel
Component: contrib.sessions Version: master
Severity: Keywords: gae, appengine
Cc: Triage Stage: Someday/Maybe
Has patch: yes Needs documentation: yes
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

Now that the cheering stopped I started implementing a session backend for Google's App Engine, obviously the easiest part in creating more compatibility between Django and GAE.

Attachments (3)

appengine_session_backend.1.jezdez.diff (5.8 KB) - added by Jannis Leidel 10 years ago.
first implementation, including documentation and tests
appengine_session_backend.2.jezdez.diff (5.8 KB) - added by Jannis Leidel 10 years ago.
Fixed stupid conditional error
appengine_session_backend.3.jezdez.diff (5.6 KB) - added by Jannis Leidel 10 years ago.
Uses session_key as key_name and Session.get_by_key_name() for better performance. Added session_key_prefix to circumvent BadArgumentError.

Download all attachments as: .zip

Change History (17)

Changed 10 years ago by Jannis Leidel

first implementation, including documentation and tests

comment:1 Changed 10 years ago by colinramsay

Owner: changed from Jannis Leidel to colinramsay
Patch needs improvement: set
Status: newassigned

I think line 107 on your patch should be "if s:" rather than "if not s:", otherwise when a matching entry is found it will still raise SuspiciousOperation and reset the session.

comment:2 Changed 10 years ago by colinramsay

Owner: colinramsay deleted
Status: assignednew

Changed 10 years ago by Jannis Leidel

Fixed stupid conditional error

comment:3 Changed 10 years ago by Jannis Leidel

Owner: set to Jannis Leidel
Patch needs improvement: unset

comment:4 Changed 10 years ago by ribrdb <ribrdb@…>

It would be more efficient to use the session_key as the key_name, and then use Session.get_by_key_name() instead of querying through Session.all()

comment:5 Changed 10 years ago by Jannis Leidel

Yes, I think so, too.

I had it implemented that way first but got "BadArgumentError: Names may not begin with a digit; received 838deafcd209c60564b730bb8b4f8fd1." exceptions from appengine and didn't want to change the way the session IDs are generated by Django.

What do you think?

comment:6 Changed 10 years ago by ribrdb <ribrdb@…>

You could add a prefix string like 'session_key:' to the django generated id.

comment:7 Changed 10 years ago by ribrdb <ribrdb@…>

Couldn't someone set settings.SESSION_COOKIE_NAME to something that starts with a number? That seems to be allowed by the RFC.

Changed 10 years ago by Jannis Leidel

Uses session_key as key_name and Session.get_by_key_name() for better performance. Added session_key_prefix to circumvent BadArgumentError.

comment:8 in reply to:  7 Changed 10 years ago by Jannis Leidel

Replying to ribrdb <ribrdb@gmail.com>:

Couldn't someone set settings.SESSION_COOKIE_NAME to something that starts with a number? That seems to be allowed by the RFC.

Right, I fixed that now :)

comment:9 Changed 10 years ago by ribrdb

I like it. It might be good though to add a test case to make sure you get the data back when you save and then load a session.

comment:10 Changed 10 years ago by makovick

AFAIK the App Engine has currently no equivalent of cron, so it would be nice if SessionStore.load is able to purge all expired sessions every once a while.
The purge timeout could be handled by the memcache API - after the cleanup, one can set some "sessions_purged" flag with 1 hour/day/whatever expiration, and then skip the purge until the flag disappears. This would avoid unnecessary datastore lookups.

comment:11 Changed 10 years ago by Marc Fargas

Brought to django-developers (here) for discussion.

comment:12 Changed 10 years ago by Marc Fargas

Needs documentation: set
Triage Stage: UnreviewedSomeday/Maybe

comment:14 Changed 10 years ago by Marc Fargas

Resolution: invalid
Status: newclosed

I take this as a "Close this until one of those alternatives requests inclusion as a contrib app" ;)

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