From 9fe2de8a1c5a76e0db562c08eb883fb83919ca7e Mon Sep 17 00:00:00 2001 From: Toby Lawrence Date: Thu, 11 Feb 2016 14:43:53 -0500 Subject: [PATCH] Don't blow away the role cache when updating. Instead of refetching the role cache fresh every time we want to add a new role to a user, just manually add the role object. We have it available to us, the model, not a distilled-down version. Add that in and leave the existing cache. --- common/djangoapps/student/roles.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/common/djangoapps/student/roles.py b/common/djangoapps/student/roles.py index c8b8796420..79b28d5e4f 100644 --- a/common/djangoapps/student/roles.py +++ b/common/djangoapps/student/roles.py @@ -54,6 +54,9 @@ class RoleCache(object): for access_role in self._roles ) + def add_role(self, role): + self._roles.add(role) + class AccessRole(object): """ @@ -157,7 +160,8 @@ class RoleBase(AccessRole): entry = CourseAccessRole(user=user, role=self._role_name, course_id=self.course_key, org=self.org) entry.save() if hasattr(user, '_roles'): - del user._roles + # del user._roles + user._roles.add_role(entry) def remove_users(self, *users): """