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.

streams: Add assert_is_not_none for stream.recipient_id.

Anders Kaseorgf32206e47e6b
diff --git a/zerver/actions/create_user.py b/zerver/actions/create_user.py
index 2261afd01c7..038afd0fb77 100644
--- a/zerver/actions/create_user.py
+++ b/zerver/actions/create_user.py
@@ -47,6 +47,7 @@ from zerver.lib.users import (
user_access_restricted_in_realm,
user_profile_to_user_row,
)
+from zerver.lib.utils import assert_is_not_none
from zerver.models import (
DefaultStreamGroup,
Message,
@@ -206,7 +207,9 @@ def add_new_user_history(
# TODO: This will do database queries in a loop if many private
# streams are involved.
recipient_ids = [
- stream.recipient_id for stream in streams if can_access_stream_history(user_profile, stream)
+ assert_is_not_none(stream.recipient_id)
+ for stream in streams
+ if can_access_stream_history(user_profile, stream)
]
# Start by finding recent messages matching those recipients.
diff --git a/zerver/actions/streams.py b/zerver/actions/streams.py
index 3eea32f894b..efc1e7f6aa1 100644
--- a/zerver/actions/streams.py
+++ b/zerver/actions/streams.py
@@ -62,6 +62,7 @@ from zerver.lib.users import (
get_subscribers_of_target_user_subscriptions,
get_users_involved_in_dms_with_target_users,
)
+from zerver.lib.utils import assert_is_not_none
from zerver.models import (
ArchivedAttachment,
Attachment,
@@ -772,8 +773,8 @@ def bulk_add_subscriptions(
for user in users:
assert user.realm_id == realm.id
- recipient_ids = [stream.recipient_id for stream in streams]
- recipient_id_to_stream = {stream.recipient_id: stream for stream in streams}
+ recipient_ids = [assert_is_not_none(stream.recipient_id) for stream in streams]
+ recipient_id_to_stream = {assert_is_not_none(stream.recipient_id): stream for stream in streams}
recipient_color_map = {}
recipient_ids_set: set[int] = set()
diff --git a/zerver/lib/streams.py b/zerver/lib/streams.py
index 82336e54137..7e4720eb884 100644
--- a/zerver/lib/streams.py
+++ b/zerver/lib/streams.py
@@ -40,6 +40,7 @@ from zerver.lib.user_groups import (
parse_group_setting_value,
user_has_permission_for_group_setting,
)
+from zerver.lib.utils import assert_is_not_none
from zerver.models import (
ChannelFolder,
DefaultStreamGroup,
@@ -1359,7 +1360,7 @@ def bulk_can_remove_subscribers_from_streams(
if not bool(permission_failure_streams):
return True
- existing_recipient_ids = [stream.recipient_id for stream in streams]
+ existing_recipient_ids = [assert_is_not_none(stream.recipient_id) for stream in streams]
sub_recipient_ids = Subscription.objects.filter(
user_profile=user_profile, recipient_id__in=existing_recipient_ids, active=True
).values_list("recipient_id", flat=True)
@@ -1454,7 +1455,7 @@ def get_metadata_access_streams(
if len(streams) == 0:
return []
- recipient_ids = [stream.recipient_id for stream in streams]
+ recipient_ids = [assert_is_not_none(stream.recipient_id) for stream in streams]
subscribed_recipient_ids = set(
Subscription.objects.filter(
user_profile=user_profile, recipient_id__in=recipient_ids, active=True
@@ -1491,7 +1492,7 @@ def get_content_access_streams(
if len(streams) == 0:
return []
- recipient_ids = [stream.recipient_id for stream in streams]
+ recipient_ids = [assert_is_not_none(stream.recipient_id) for stream in streams]
subscribed_recipient_ids = set(
Subscription.objects.filter(
user_profile=user_profile, recipient_id__in=recipient_ids, active=True