typing: Add none-checks for stream.recipient_id.

Signed-off-by: Zixuan James Li <p359101898@gmail.com>
This commit is contained in:
Zixuan James Li
2022-06-14 22:59:36 -04:00
committed by Tim Abbott
parent 944e602788
commit 058dab5818
7 changed files with 9 additions and 0 deletions

View File

@@ -506,6 +506,7 @@ def do_update_message(
edit_history_event["prev_stream"] = stream_being_edited.id edit_history_event["prev_stream"] = stream_being_edited.id
edit_history_event["stream"] = new_stream.id edit_history_event["stream"] = new_stream.id
event[ORIG_TOPIC] = orig_topic_name event[ORIG_TOPIC] = orig_topic_name
assert new_stream.recipient_id is not None
target_message.recipient_id = new_stream.recipient_id target_message.recipient_id = new_stream.recipient_id
event["new_stream_id"] = new_stream.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 # query. But it's nice to reuse code, and this bulk
# operation is likely cheaper than a `GET /messages` # operation is likely cheaper than a `GET /messages`
# unless the topic has thousands of messages of history. # unless the topic has thousands of messages of history.
assert stream_being_edited.recipient_id is not None
unmoved_messages = messages_for_topic( unmoved_messages = messages_for_topic(
stream_being_edited.recipient_id, stream_being_edited.recipient_id,
orig_topic_name, orig_topic_name,

View File

@@ -789,6 +789,7 @@ def do_change_stream_permission(
if old_invite_only_value != stream.invite_only: if old_invite_only_value != stream.invite_only:
# Reset the Attachment.is_realm_public cache for all # Reset the Attachment.is_realm_public cache for all
# messages in the stream whose permissions were changed. # 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( Attachment.objects.filter(messages__recipient_id=stream.recipient_id).update(
is_realm_public=None is_realm_public=None
) )
@@ -832,6 +833,7 @@ def do_change_stream_permission(
if old_is_web_public_value != stream.is_web_public: if old_is_web_public_value != stream.is_web_public:
# Reset the Attachment.is_realm_public cache for all # Reset the Attachment.is_realm_public cache for all
# messages in the stream whose permissions were changed. # 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( Attachment.objects.filter(messages__recipient_id=stream.recipient_id).update(
is_web_public=None is_web_public=None
) )

View File

@@ -19,6 +19,7 @@ def do_mute_topic(
) -> None: ) -> None:
if date_muted is None: if date_muted is None:
date_muted = timezone_now() date_muted = timezone_now()
assert stream.recipient_id is not None
add_topic_mute( add_topic_mute(
user_profile, user_profile,
stream.id, stream.id,

View File

@@ -358,6 +358,7 @@ def access_stream_common(
raise AssertionError("user_profile and stream realms don't match") raise AssertionError("user_profile and stream realms don't match")
try: try:
assert stream.recipient_id is not None
sub = Subscription.objects.get( sub = Subscription.objects.get(
user_profile=user_profile, recipient_id=stream.recipient_id, active=require_active user_profile=user_profile, recipient_id=stream.recipient_id, active=require_active
) )

View File

@@ -271,6 +271,7 @@ def most_recent_message(user_profile: UserProfile) -> Message:
def get_subscription(stream_name: str, user_profile: UserProfile) -> Subscription: def get_subscription(stream_name: str, user_profile: UserProfile) -> Subscription:
stream = get_stream(stream_name, user_profile.realm) stream = get_stream(stream_name, user_profile.realm)
recipient_id = stream.recipient_id recipient_id = stream.recipient_id
assert recipient_id is not None
return Subscription.objects.get( return Subscription.objects.get(
user_profile=user_profile, recipient_id=recipient_id, active=True user_profile=user_profile, recipient_id=recipient_id, active=True
) )

View File

@@ -49,6 +49,7 @@ def set_topic_mutes(
for stream_name, topic_name in muted_topics: for stream_name, topic_name in muted_topics:
stream = get_stream(stream_name, user_profile.realm) stream = get_stream(stream_name, user_profile.realm)
recipient_id = stream.recipient_id recipient_id = stream.recipient_id
assert recipient_id is not None
add_topic_mute( add_topic_mute(
user_profile=user_profile, user_profile=user_profile,

View File

@@ -792,6 +792,7 @@ def get_topics_backend(
(stream, sub) = access_stream_by_id(user_profile, stream_id) (stream, sub) = access_stream_by_id(user_profile, stream_id)
assert stream.recipient_id is not None
result = get_topic_history_for_stream( result = get_topic_history_for_stream(
user_profile=user_profile, user_profile=user_profile,
recipient_id=stream.recipient_id, recipient_id=stream.recipient_id,