Code

Opened 6 years ago

Closed 6 years ago

#7008 closed (invalid)

Add session backend for Google's App Engine

Reported by: jezdez Owned by: jezdez
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 jezdez 6 years ago.
first implementation, including documentation and tests
appengine_session_backend.2.jezdez.diff (5.8 KB) - added by jezdez 6 years ago.
Fixed stupid conditional error
appengine_session_backend.3.jezdez.diff (5.6 KB) - added by jezdez 6 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 6 years ago by jezdez

first implementation, including documentation and tests

comment:1 Changed 6 years ago by colinramsay

  • Needs documentation unset
  • Needs tests unset
  • Owner changed from jezdez to colinramsay
  • Patch needs improvement set
  • Status changed from new to assigned

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

  • Owner colinramsay deleted
  • Status changed from assigned to new

Changed 6 years ago by jezdez

Fixed stupid conditional error

comment:3 Changed 6 years ago by jezdez

  • Owner set to jezdez
  • Patch needs improvement unset

comment:4 Changed 6 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 6 years ago by jezdez

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 6 years ago by ribrdb <ribrdb@…>

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

comment:7 follow-up: Changed 6 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 6 years ago by jezdez

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

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

Brought to django-developers (here) for discussion.

comment:12 Changed 6 years ago by telenieko

  • Needs documentation set
  • Triage Stage changed from Unreviewed to Someday/Maybe

comment:14 Changed 6 years ago by telenieko

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

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

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.