diff --git a/zerver/actions/message_edit.py b/zerver/actions/message_edit.py index 1772f4aceb..d16a711813 100644 --- a/zerver/actions/message_edit.py +++ b/zerver/actions/message_edit.py @@ -506,6 +506,7 @@ def do_update_message( edit_history_event["prev_stream"] = stream_being_edited.id edit_history_event["stream"] = new_stream.id event[ORIG_TOPIC] = orig_topic_name + assert new_stream.recipient_id is not None target_message.recipient_id = new_stream.recipient_id event["new_stream_id"] = new_stream.id @@ -762,6 +763,7 @@ def do_update_message( # query. But it's nice to reuse code, and this bulk # operation is likely cheaper than a `GET /messages` # unless the topic has thousands of messages of history. + assert stream_being_edited.recipient_id is not None unmoved_messages = messages_for_topic( stream_being_edited.recipient_id, orig_topic_name, diff --git a/zerver/actions/streams.py b/zerver/actions/streams.py index 51ea3d53cf..6b3602b703 100644 --- a/zerver/actions/streams.py +++ b/zerver/actions/streams.py @@ -789,6 +789,7 @@ def do_change_stream_permission( if old_invite_only_value != stream.invite_only: # Reset the Attachment.is_realm_public cache for all # messages in the stream whose permissions were changed. + assert stream.recipient_id is not None Attachment.objects.filter(messages__recipient_id=stream.recipient_id).update( is_realm_public=None ) @@ -832,6 +833,7 @@ def do_change_stream_permission( if old_is_web_public_value != stream.is_web_public: # Reset the Attachment.is_realm_public cache for all # messages in the stream whose permissions were changed. + assert stream.recipient_id is not None Attachment.objects.filter(messages__recipient_id=stream.recipient_id).update( is_web_public=None ) diff --git a/zerver/actions/user_topics.py b/zerver/actions/user_topics.py index 5e18c90139..ec00e5db7a 100644 --- a/zerver/actions/user_topics.py +++ b/zerver/actions/user_topics.py @@ -19,6 +19,7 @@ def do_mute_topic( ) -> None: if date_muted is None: date_muted = timezone_now() + assert stream.recipient_id is not None add_topic_mute( user_profile, stream.id, diff --git a/zerver/lib/streams.py b/zerver/lib/streams.py index f0e5d835cc..f98044857b 100644 --- a/zerver/lib/streams.py +++ b/zerver/lib/streams.py @@ -358,6 +358,7 @@ def access_stream_common( raise AssertionError("user_profile and stream realms don't match") try: + assert stream.recipient_id is not None sub = Subscription.objects.get( user_profile=user_profile, recipient_id=stream.recipient_id, active=require_active ) diff --git a/zerver/lib/test_helpers.py b/zerver/lib/test_helpers.py index 61bf77d00a..051b3ed6ed 100644 --- a/zerver/lib/test_helpers.py +++ b/zerver/lib/test_helpers.py @@ -271,6 +271,7 @@ def most_recent_message(user_profile: UserProfile) -> Message: def get_subscription(stream_name: str, user_profile: UserProfile) -> Subscription: stream = get_stream(stream_name, user_profile.realm) recipient_id = stream.recipient_id + assert recipient_id is not None return Subscription.objects.get( user_profile=user_profile, recipient_id=recipient_id, active=True ) diff --git a/zerver/lib/user_topics.py b/zerver/lib/user_topics.py index 0ead16824e..18595a8ad8 100644 --- a/zerver/lib/user_topics.py +++ b/zerver/lib/user_topics.py @@ -49,6 +49,7 @@ def set_topic_mutes( for stream_name, topic_name in muted_topics: stream = get_stream(stream_name, user_profile.realm) recipient_id = stream.recipient_id + assert recipient_id is not None add_topic_mute( user_profile=user_profile, diff --git a/zerver/views/streams.py b/zerver/views/streams.py index ec573b2889..d301bddf60 100644 --- a/zerver/views/streams.py +++ b/zerver/views/streams.py @@ -792,6 +792,7 @@ def get_topics_backend( (stream, sub) = access_stream_by_id(user_profile, stream_id) + assert stream.recipient_id is not None result = get_topic_history_for_stream( user_profile=user_profile, recipient_id=stream.recipient_id,