From 577555e5293c5601b30109d9ab1c9d413d494094 Mon Sep 17 00:00:00 2001 From: Sahil Batra Date: Wed, 12 Jul 2023 15:32:10 +0530 Subject: [PATCH] send_custom_email: Pass realm as arg to select_related. This commit updates the select_related calls in queries to get UserProfile objects in send_custom_email code to pass "realm" as argument to select_related call. Also, note that "realm" is the only non-null foreign key field in UserProfile object, so select_related() was only fetching realm object previously as well. But we should still pass "realm" as argument in select_related call so that we can make sure that only required fields are selected in case we add more foreign keys to UserProfile in future. --- zerver/management/commands/send_custom_email.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zerver/management/commands/send_custom_email.py b/zerver/management/commands/send_custom_email.py index 7fd04aa2e7..cc830c94a5 100644 --- a/zerver/management/commands/send_custom_email.py +++ b/zerver/management/commands/send_custom_email.py @@ -129,7 +129,7 @@ class Command(ZulipBaseCommand): # We need to do a new query because the `get_users` path # passes us a list rather than a QuerySet. users = ( - UserProfile.objects.select_related() + UserProfile.objects.select_related("realm") .filter(id__in=[u.id for u in users]) .exclude( Q(tos_version=None) | Q(tos_version=UserProfile.TOS_VERSION_BEFORE_FIRST_LOGIN)