diff --git a/mypy.ini b/mypy.ini index 43af608d41..56470f7937 100644 --- a/mypy.ini +++ b/mypy.ini @@ -312,7 +312,7 @@ strict_optional = True [mypy-zerver.lib.avatar] # str vs Optional[str] strict_optional = True [mypy-zerver.lib.soft_deactivation] -strict_optional = False +strict_optional = True [mypy-zerver.lib.events] # signup_notifications_stream is Optional, but accessing id property strict_optional = True [mypy-zerver.lib.exceptions] #21: error: Return type of "__reduce_ex__" incompatible with supertype "object" diff --git a/zerver/lib/soft_deactivation.py b/zerver/lib/soft_deactivation.py index f4d8149b41..6e4d442c35 100644 --- a/zerver/lib/soft_deactivation.py +++ b/zerver/lib/soft_deactivation.py @@ -97,6 +97,7 @@ def add_missing_messages(user_profile: UserProfile) -> None: * Create the UserMessage rows. """ + assert user_profile.last_active_message_id is not None all_stream_subs = list(Subscription.objects.select_related('recipient').filter( user_profile=user_profile, recipient__type=Recipient.STREAM).values('recipient', 'recipient__type_id')) @@ -118,11 +119,12 @@ def add_missing_messages(user_profile: UserProfile) -> None: recipient_ids = [] for sub in all_stream_subs: stream_subscription_logs = all_stream_subscription_logs[sub['recipient__type_id']] - if (stream_subscription_logs[-1].event_type == 'subscription_deactivated' and - stream_subscription_logs[-1].event_last_message_id <= user_profile.last_active_message_id): - # We are going to short circuit this iteration as its no use - # iterating since user unsubscribed before soft-deactivation - continue + if stream_subscription_logs[-1].event_type == 'subscription_deactivated': + assert stream_subscription_logs[-1].event_last_message_id is not None + if stream_subscription_logs[-1].event_last_message_id <= user_profile.last_active_message_id: + # We are going to short circuit this iteration as its no use + # iterating since user unsubscribed before soft-deactivation + continue recipient_ids.append(sub['recipient']) all_stream_msgs = list(Message.objects.select_related(