aboutsummaryrefslogtreecommitdiffstats
path: root/mediagoblin/tools/request.py
diff options
context:
space:
mode:
authorElrond <elrond+mediagoblin.org@samba-tng.org>2012-01-13 22:59:14 +0100
committerElrond <elrond+mediagoblin.org@samba-tng.org>2012-01-14 13:36:00 +0100
commit52fc51f6a9b6379d39d391bd54473eebb6d23cd5 (patch)
tree1e021d353fb4c699faa7df5f91f2604d675e5b0d /mediagoblin/tools/request.py
parent9c947004139d0d0ae5a879cd4c120891f8a8d51e (diff)
downloadmediagoblin-52fc51f6a9b6379d39d391bd54473eebb6d23cd5.tar.lz
mediagoblin-52fc51f6a9b6379d39d391bd54473eebb6d23cd5.tar.xz
mediagoblin-52fc51f6a9b6379d39d391bd54473eebb6d23cd5.zip
Drop sessions with invalid ObjectIds
The session can contain invalid objectids when switching a more or less live instance (with logged in users) from mongo to sql or vice versa. So drop the complete session and force the user to login again.
Diffstat (limited to 'mediagoblin/tools/request.py')
-rw-r--r--mediagoblin/tools/request.py12
1 files changed, 8 insertions, 4 deletions
diff --git a/mediagoblin/tools/request.py b/mediagoblin/tools/request.py
index b1cbe119..7e193125 100644
--- a/mediagoblin/tools/request.py
+++ b/mediagoblin/tools/request.py
@@ -14,7 +14,7 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
-from mediagoblin.db.util import ObjectId
+from mediagoblin.db.util import ObjectId, InvalidId
def setup_user_in_request(request):
"""
@@ -25,13 +25,17 @@ def setup_user_in_request(request):
request.user = None
return
- user = None
- user = request.app.db.User.one(
- {'_id': ObjectId(request.session['user_id'])})
+ try:
+ oid = ObjectId(request.session['user_id'])
+ except InvalidId:
+ user = None
+ else:
+ user = request.db.User.one({'_id': oid})
if not user:
# Something's wrong... this user doesn't exist? Invalidate
# this session.
+ print "Killing session for %r" % request.session['user_id']
request.session.invalidate()
request.user = user