Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
do_change_user_role: Fix clunky select_for_update+refresh_from_db code.
Mateusz Mandera522340d85748
diff --git a/zerver/actions/users.py b/zerver/actions/users.pyindex 76b10e6b363..652dbc2c6a7 100644--- a/zerver/actions/users.py+++ b/zerver/actions/users.py@@ -621,14 +621,8 @@ def do_change_user_role() -> None:# We want to both (a) take a lock on the UserProfile row, and (b)# modify the passed-in UserProfile object, so that callers see the- # changes in the object they hold. Unfortunately,- # `select_for_update` cannot be combined with `refresh_from_db`- # (https://code.djangoproject.com/ticket/28344). Call- # `select_for_update` and throw away the result, so that we know- # we have the lock on the row, then re-fill the `user_profile`- # object with the values now that the lock exists.- UserProfile.objects.select_for_update().get(id=user_profile.id)- user_profile.refresh_from_db()+ # changes in the object they hold.+ user_profile.refresh_from_db(from_queryset=UserProfile.objects.select_for_update(no_key=True))old_value = user_profile.roleif old_value == value: