Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Browse files

modified sessions to look for a valid db object either passed as an a…

…rgument, as an attribute of the request object or as an attribute of the request objects application attribute
  • Loading branch information...
commit 8abb32ee4e5d49e203f1136c3c27b63a5acea625 1 parent 3ecaeb5
@joerussbowman authored
Showing with 17 additions and 6 deletions.
  1. +17 −6 sessions/
23 sessions/
@@ -63,16 +63,20 @@ def __init__(self, req_obj,
+ db=None,
__init__ loads the session, checking the browser for a valid session
token. It will either validate the session and/or create a new one
if necessary.
- Currently AsyncMongoSession expects a db attribute on the request
- object which is an AsyncMongo connection. This is just how I'm using
- it. If other developers start using this library then I will consider
- making the db connection passed as an argument or something.
+ The db object should be a mongodb database, not collection. The
+ collection value is set by the settings for the library. See
+ for more information.
+ If you already have a db attribute on the request or application
+ objects then there is no need to pass it. Sessions will automatically
+ check those objects for a valid database object to use.
self.req_obj = req_obj
self.cookie_path = cookie_path
@@ -80,7 +84,14 @@ def __init__(self, req_obj,
self.session_token_ttl = session_token_ttl
self.session_expire_time = session_expire_time
self.callback = callback
- self.db = self.req_obj.db[mongo_collection]
+ if db:
+ self.db = db[mongo_collection]
+ elif hasattr(self.req_obj, "db"):
+ self.db = self.req_obj.db[mongo_collection]
+ elif hasattr(self.req_obj.application, "db"):
+ self.db = self.req_obj.application.db[mongo_collection]
+ else:
+ raise ValueError("Invalid value for db")
self.new_session = True
self.do_put = False

0 comments on commit 8abb32e

Please sign in to comment.
Something went wrong with that request. Please try again.