diff --git a/zerver/actions/create_user.py b/zerver/actions/create_user.py index cba54d754c..c1be320253 100644 --- a/zerver/actions/create_user.py +++ b/zerver/actions/create_user.py @@ -776,7 +776,9 @@ def do_reactivate_user(user_profile: UserProfile, *, acting_user: UserProfile | subscriber_peer_info=subscriber_peer_info, ) - member_user_groups = user_profile.direct_groups.select_related("named_user_group") + member_user_groups = user_profile.direct_groups.select_related("named_user_group").order_by( + "id" + ) named_user_groups = [] setting_user_groups = [] for group in member_user_groups: diff --git a/zerver/actions/users.py b/zerver/actions/users.py index bb7af6461c..81ae6a0ef7 100644 --- a/zerver/actions/users.py +++ b/zerver/actions/users.py @@ -427,7 +427,9 @@ def send_events_for_user_deactivation(user_profile: UserProfile) -> None: # data, but guests who cannot access the deactivated user # need an explicit 'user_group/remove_members' event to # update the user groups data. - deactivated_user_groups = user_profile.direct_groups.select_related("named_user_group") + deactivated_user_groups = user_profile.direct_groups.select_related( + "named_user_group" + ).order_by("id") deactivated_user_named_groups = [] deactivated_user_setting_groups = [] for group in deactivated_user_groups: