Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Correct a bug in unify_users that sometimes causes users to log in tw…

…ice in a row
  • Loading branch information...
commit 6506ef2fc3beaa8f97d27d32cdea712391ff0e78 1 parent 63ba846
Chris Northwood cnorthwood authored
Showing with 8 additions and 2 deletions.
  1. +8 −2 molly/auth/utils.py
10 molly/auth/utils.py
View
@@ -21,8 +21,14 @@ def unify_users(request):
identifier_namespaces = set(i.namespace for i in user.useridentifier_set.all())
root_user = min(users, key=lambda u:u.date_joined)
-
- for u in users:
+
+ # Need to do the root_user first, otherwise if it's after the current user,
+ # tokens get assigned from the current user to the root user, and then
+ # removed from the root user, because it's not the current user.
+ # We accomplish this by sorting the set into a list, with a custom
+ # comparison function which gives the root_user the lowest value (and so is
+ # first)
+ for u in sorted(users, cmp=lambda x, y: -1 if x == root_user else 1 if y == root_user else 0):
u.usersession_set.all().update(user=root_user)
Please sign in to comment.
Something went wrong with that request. Please try again.