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.
This commit is contained in:
Sahil Batra 2023-07-12 15:32:10 +05:30 committed by Tim Abbott
parent 3ae0b4f913
commit 577555e529
1 changed files with 1 additions and 1 deletions

View File

@ -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)