Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

typing: Avoid redefinition of incompatible QuerySets.

Zixuan James Li6c7b2d621e31
diff --git a/zerver/lib/cache.py b/zerver/lib/cache.py
index 33fbec33555..7997e1f70c3 100644
--- a/zerver/lib/cache.py
+++ b/zerver/lib/cache.py
@@ -571,8 +571,9 @@ def delete_user_profile_caches(user_profiles: Iterable["UserProfile"]) -> None:
def delete_display_recipient_cache(user_profile: "UserProfile") -> None:
from zerver.models import Subscription # We need to import here to avoid cyclic dependency.
- recipient_ids = Subscription.objects.filter(user_profile=user_profile)
- recipient_ids = recipient_ids.values_list("recipient_id", flat=True)
+ recipient_ids = Subscription.objects.filter(user_profile=user_profile).values_list(
+ "recipient_id", flat=True
+ )
keys = [display_recipient_cache_key(rid) for rid in recipient_ids]
keys.append(display_recipient_bulk_get_users_by_id_cache_key(user_profile.id))
cache_delete_many(keys)
diff --git a/zerver/lib/email_notifications.py b/zerver/lib/email_notifications.py
index 372ca2bab99..32a57a2fb2a 100644
--- a/zerver/lib/email_notifications.py
+++ b/zerver/lib/email_notifications.py
@@ -560,10 +560,8 @@ def handle_missedmessage_emails(
usermessage__user_profile_id=user_profile,
id__in=message_ids,
usermessage__flags=~UserMessage.flags.read,
- )
-
- # Cancel missed-message emails for deleted messages
- messages = [um for um in messages if um.content != "(deleted)"]
+ # Cancel missed-message emails for deleted messages
+ ).exclude(content="(deleted)")
if not messages:
return
diff --git a/zerver/lib/events.py b/zerver/lib/events.py
index 2afe7c2592a..89018a58c14 100644
--- a/zerver/lib/events.py
+++ b/zerver/lib/events.py
@@ -164,7 +164,7 @@ def fetch_initial_state_data(
# `max_message_id` is primarily used for generating `local_id`
# values that are higher than this. We likely can eventually
# remove this parameter from the API.
- user_messages = []
+ user_messages = None
if user_profile is not None:
user_messages = (
UserMessage.objects.filter(user_profile=user_profile)
diff --git a/zerver/lib/export.py b/zerver/lib/export.py
index c6ec862555b..1866abc8d1e 100644
--- a/zerver/lib/export.py
+++ b/zerver/lib/export.py
@@ -1245,8 +1245,8 @@ def export_partial_message_files(
user_profile_id__in=consented_user_ids
).values_list("recipient_id", flat=True)
- recipient_ids = set(public_stream_recipient_ids) | set(consented_recipient_ids)
- recipient_ids_for_us = get_ids(response["zerver_recipient"]) & recipient_ids
+ recipient_ids_set = set(public_stream_recipient_ids) | set(consented_recipient_ids)
+ recipient_ids_for_us = get_ids(response["zerver_recipient"]) & recipient_ids_set
else:
recipient_ids_for_us = get_ids(response["zerver_recipient"])
# For a full export, we have implicit consent for all users in the export.
diff --git a/zerver/lib/management.py b/zerver/lib/management.py
index a6a54b35e23..24a4a9c2f3c 100644
--- a/zerver/lib/management.py
+++ b/zerver/lib/management.py
@@ -140,10 +140,7 @@ server via `ps -ef` or reading bash history. Prefer
if options["users"] is None:
return []
emails = {email.strip() for email in options["users"].split(",")}
- user_profiles = []
- for email in emails:
- user_profiles.append(self.get_user(email, realm))
- return user_profiles
+ return [self.get_user(email, realm) for email in emails]
def get_user(self, email: str, realm: Optional[Realm]) -> UserProfile:
diff --git a/zerver/lib/presence.py b/zerver/lib/presence.py
index e0f8f9ab7fc..051ff82fd7e 100644
--- a/zerver/lib/presence.py
+++ b/zerver/lib/presence.py
@@ -177,12 +177,12 @@ def get_status_dict_by_realm(
# a realm with 0 active users.
return {}
- mobile_query = query_for_ids(
+ mobile_query_ids = query_for_ids(
query=mobile_query,
user_ids=user_profile_ids,
field="user_id",
)
- mobile_user_ids = set(mobile_query)
+ mobile_user_ids = set(mobile_query_ids)
return get_status_dicts_for_rows(presence_rows, mobile_user_ids, slim_presence)
diff --git a/zerver/lib/user_topics.py b/zerver/lib/user_topics.py
index 1be90da4c67..f67d897f07a 100644
--- a/zerver/lib/user_topics.py
+++ b/zerver/lib/user_topics.py
@@ -121,11 +121,9 @@ def exclude_topic_mutes(
# by not considering topic mutes outside the stream.
query = query.filter(stream_id=stream_id)
- rows = list(
- query.values(
- "recipient_id",
- "topic_name",
- )
+ rows = query.values(
+ "recipient_id",
+ "topic_name",
)
if not rows:
@@ -153,7 +151,6 @@ def build_topic_mute_checker(user_profile: UserProfile) -> Callable[[int, str],
"recipient_id",
"topic_name",
)
- rows = list(rows)
tups = set()
for row in rows: