Skip to content

Commit 9968fb5

Browse files
committed
send_custom_email: Fix emailing single users with TOS_VERSION set.
This code path previously threw an exception.
1 parent fae92f2 commit 9968fb5

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

zerver/management/commands/send_custom_email.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,13 @@ def handle(self, *args: Any, **options: str) -> None:
111111

112112
# Only email users who've agreed to the terms of service.
113113
if settings.TOS_VERSION is not None:
114-
users = users.exclude(tos_version=None)
114+
# We need to do a new query because the `get_users` path
115+
# passes us a list rather than a QuerySet.
116+
users = (
117+
UserProfile.objects.select_related()
118+
.filter(id__in=[u.id for u in users])
119+
.exclude(tos_version=None)
120+
)
115121
send_custom_email(users, options)
116122

117123
if options["dry_run"]:

0 commit comments

Comments
 (0)