From 7f3bb4523c89e04c1cfce0f4807d5032dc27acfe Mon Sep 17 00:00:00 2001 From: Anders Kaseorg Date: Fri, 19 Sep 2025 18:47:19 -0700 Subject: [PATCH] update_subscriber_counts: Fix union typing. Signed-off-by: Anders Kaseorg --- zerver/management/commands/update_subscriber_counts.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/zerver/management/commands/update_subscriber_counts.py b/zerver/management/commands/update_subscriber_counts.py index 2ca11a6843..6bd3518eee 100644 --- a/zerver/management/commands/update_subscriber_counts.py +++ b/zerver/management/commands/update_subscriber_counts.py @@ -5,7 +5,7 @@ from typing import Any from django.conf import settings from django.db import transaction -from django.db.models import QuerySet +from django.db.models import F, QuerySet from django.utils.timezone import now as timezone_now from typing_extensions import override @@ -85,10 +85,12 @@ accurate; this command is run as a daily cron job to ensure the number is accura streams_from_users = streams_from_users.filter(realm=realm) stream_ids: QuerySet[Any, int] = ( - changed_subs.values_list("modified_stream_id", flat=True) - .distinct() + changed_subs.distinct("modified_stream_id") .order_by("modified_stream_id") - ).union(streams_from_users.values_list("id", flat=True)) + .annotate(stream_id=F("modified_stream_id")) + .union(streams_from_users.annotate(stream_id="id")) + .values_list("stream_id", flat=True) + ) elif realm := self.get_realm(options): stream_ids = streams.filter(realm=realm).values_list("id", flat=True) else: