Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
migrations: Drop UserProfile.recipient and personal recipient rows.
Alex Vandiverc6d41065997f
diff --git a/zerver/actions/realm_settings.py b/zerver/actions/realm_settings.pyindex 45db56e74f1..a5051e5ff23 100644--- a/zerver/actions/realm_settings.py+++ b/zerver/actions/realm_settings.py@@ -779,7 +779,6 @@ def do_scrub_realm(realm: Realm, *, acting_user: UserProfile | None) -> None:Stream.objects.filter(realm=realm).values_list("recipient_id", flat=True).union(- UserProfile.objects.filter(realm=realm).values_list("recipient_id", flat=True),Subscription.objects.filter(recipient__type=Recipient.DIRECT_MESSAGE_GROUP, user_profile__realm=realm).values_list("recipient_id", flat=True),diff --git a/zerver/data_import/user_handler.py b/zerver/data_import/user_handler.pyindex fb5d413d453..385ef74215b 100644--- a/zerver/data_import/user_handler.py+++ b/zerver/data_import/user_handler.py@@ -15,19 +15,11 @@ class UserHandler:def __init__(self) -> None:self.id_to_user_map: dict[int, dict[str, Any]] = {}- self.exported_user_id_to_zulip_recipient_id: dict[str, int] = {}def add_user(self, user: dict[str, Any]) -> None:user_id = user["id"]self.id_to_user_map[user_id] = user- def add_exported_user_id_to_zulip_recipient_id(- self, exported_user_id: str, zulip_recipient_id: int- ) -> None:- # TODO: Currently only Mattermost importer uses this. Maybe refactor this into- # self.add_user() once other importers are using this method too.- self.exported_user_id_to_zulip_recipient_id[exported_user_id] = zulip_recipient_id-def get_user(self, user_id: int) -> dict[str, Any]:user = self.id_to_user_map[user_id]return userdiff --git a/zerver/lib/email_mirror.py b/zerver/lib/email_mirror.pyindex 5bcdffbe757..a3b9e3c767f 100644--- a/zerver/lib/email_mirror.py+++ b/zerver/lib/email_mirror.py@@ -136,7 +136,6 @@ def get_usable_missed_message_address(address: str) -> MissedMessageEmailAddress"message","message__sender","message__recipient",- "message__sender__recipient",).get(email_token=token)except MissedMessageEmailAddress.DoesNotExist:raise ZulipEmailForwardError("Zulip notification reply address is invalid.")diff --git a/zerver/lib/import_realm.py b/zerver/lib/import_realm.pyindex 3c6ba6288e0..e5d90636292 100644--- a/zerver/lib/import_realm.py+++ b/zerver/lib/import_realm.py@@ -1384,13 +1384,6 @@ def do_import_realm(import_dir: Path, subdomain: str, processes: int = 1) -> Reanew_user_id = get_system_bot(item["email"], internal_realm.id).idupdate_id_map(table="user_profile", old_id=item["id"], new_id=new_user_id)crossrealm_user_ids.add(new_user_id)- try:- new_recipient_id = Recipient.objects.get(- type=Recipient.PERSONAL, type_id=new_user_id- ).id- update_id_map(table="recipient", old_id=item["recipient_id"], new_id=new_recipient_id)- except Recipient.DoesNotExist:- assert item["recipient_id"] is None# We first do a pass of updating model IDs for the cluster of# major models that have foreign keys into each other.diff --git a/zerver/lib/message_cache.py b/zerver/lib/message_cache.pyindex c9ec0f3cd6c..dea8d6c4bc5 100644--- a/zerver/lib/message_cache.py+++ b/zerver/lib/message_cache.py@@ -478,7 +478,6 @@ class MessageDict:"full_name","delivery_email","email",- "recipient_id","realm__string_id","avatar_source","avatar_version",diff --git a/zerver/lib/push_notifications.py b/zerver/lib/push_notifications.pyindex a600e0ea15e..7a7ca38e01f 100644--- a/zerver/lib/push_notifications.py+++ b/zerver/lib/push_notifications.py@@ -1720,7 +1720,6 @@ def handle_push_notification(user_profile_id: int, missed_message: dict[str, Any"subject","rendered_content","date_sent",- "sender__recipient_id","sender__realm_id","sender__is_bot","sender__email",diff --git a/zerver/lib/test_classes.py b/zerver/lib/test_classes.pyindex 0de6c9eea8a..96756566e86 100644--- a/zerver/lib/test_classes.py+++ b/zerver/lib/test_classes.py@@ -2867,6 +2867,9 @@ class PushNotificationTestCase(BouncerTestCase):self.sending_client = get_client("test")self.sender = self.example_user("hamlet")self.dm_recipient_user = self.example_user("othello")+ self.dm_group = get_or_create_direct_message_group(+ [self.sender.id, self.dm_recipient_user.id]+ )def get_message(self, type: int, type_id: int, realm_id: int) -> Message:recipient, _ = Recipient.objects.get_or_create(diff --git a/zerver/lib/test_helpers.py b/zerver/lib/test_helpers.pyindex d337fe05869..0812d158c98 100644--- a/zerver/lib/test_helpers.py+++ b/zerver/lib/test_helpers.py@@ -677,7 +677,6 @@ def use_db_models(RealmEmoji = apps.get_model("zerver", "RealmEmoji")RealmFilter = apps.get_model("zerver", "RealmFilter")Recipient = apps.get_model("zerver", "Recipient")- Recipient.PERSONAL = 1Recipient.STREAM = 2Recipient.DIRECT_MESSAGE_GROUP = 3ScheduledEmail = apps.get_model("zerver", "ScheduledEmail")diff --git a/zerver/migrations/0182_set_initial_value_is_private_flag.py b/zerver/migrations/0182_set_initial_value_is_private_flag.pyindex 5181a1ad242..7db9615b01b 100644--- a/zerver/migrations/0182_set_initial_value_is_private_flag.py+++ b/zerver/migrations/0182_set_initial_value_is_private_flag.py@@ -3,6 +3,9 @@ from django.db.backends.base.schema import BaseDatabaseSchemaEditorfrom django.db.migrations.state import StateAppsfrom django.db.models import F+RECIPIENT_PERSONAL = 1+RECIPIENT_HUDDLE = 3+def set_initial_value_of_is_private_flag(apps: StateApps, schema_editor: BaseDatabaseSchemaEditor@@ -20,9 +23,12 @@ def set_initial_value_of_is_private_flag(print("\nStart setting initial value for is_private flag...", flush=True)while True:range_end = i + 10000- # Can't use [Recipient.PERSONAL, Recipient.DIRECT_MESSAGE_GROUP] in migration filesmessage_ids = list(- Message.objects.filter(recipient__type__in=[1, 3], id__gt=i, id__lte=range_end)+ Message.objects.filter(+ recipient__type__in=[RECIPIENT_PERSONAL, RECIPIENT_HUDDLE],+ id__gt=i,+ id__lte=range_end,+ ).values_list("id", flat=True).order_by("id"))diff --git a/zerver/migrations/0798_remove_userprofile_recipient_and_personal_recipients.py b/zerver/migrations/0798_remove_userprofile_recipient_and_personal_recipients.pynew file mode 100644index 00000000000..cd5427063bd--- /dev/null+++ b/zerver/migrations/0798_remove_userprofile_recipient_and_personal_recipients.py@@ -0,0 +1,72 @@+from django.db import connection, migrations+from django.db.backends.base.schema import BaseDatabaseSchemaEditor+from django.db.migrations.state import StateApps+from psycopg2.sql import SQL++PERSONAL_RECIPIENT_TYPE = 1+BATCH_SIZE = 5000+++def delete_personal_recipient_data(+ apps: StateApps, schema_editor: BaseDatabaseSchemaEditor+) -> None:+ """Delete Subscription rows and then Recipient rows for personal recipients.++ Done in batches to avoid long-running transactions on large+ deployments.+ """+ with connection.cursor() as cursor:+ while True:+ cursor.execute(+ SQL(+ """+ DELETE FROM zerver_subscription+ WHERE id IN (+ SELECT s.id FROM zerver_subscription s+ JOIN zerver_recipient r ON s.recipient_id = r.id+ WHERE r.type = %s+ LIMIT %s+ )+ """+ ),+ [PERSONAL_RECIPIENT_TYPE, BATCH_SIZE],+ )+ if cursor.rowcount == 0:+ break++ while True:+ cursor.execute(+ SQL(+ """+ DELETE FROM zerver_recipient+ WHERE id IN (+ SELECT id FROM zerver_recipient+ WHERE type = %s+ LIMIT %s+ )+ """+ ),+ [PERSONAL_RECIPIENT_TYPE, BATCH_SIZE],+ )+ if cursor.rowcount == 0:+ break+++class Migration(migrations.Migration):+ atomic = False++ dependencies = [+ ("zerver", "0797_userprofile_is_deleted"),+ ]++ operations = [+ migrations.RemoveField(+ model_name="userprofile",+ name="recipient",+ ),+ migrations.RunPython(+ delete_personal_recipient_data,+ reverse_code=migrations.RunPython.noop,+ elidable=True,+ ),+ ]diff --git a/zerver/models/recipients.py b/zerver/models/recipients.pyindex 5f8df249deb..1ef1ca13593 100644--- a/zerver/models/recipients.py+++ b/zerver/models/recipients.py@@ -21,19 +21,14 @@ class Recipient(models.Model):of audiences Zulip supports for a message.Recipient has just two attributes: The enum type, and a type_id,- which is the ID of the UserProfile/Stream/DirectMessageGroup object- containing all the metadata for the audience. There are 3 recipient- types:-- 1. 1:1 direct message: The type_id is the ID of the UserProfile- who will receive any message to this Recipient. The sender- of such a message is represented separately.- 2. Stream message: The type_id is the ID of the associated Stream.- 3. Group direct message: In Zulip, group direct messages are- represented by DirectMessageGroup objects, which encode the set of- users in the conversation. The type_id is the ID of the associated- DirectMessageGroup object; the set of users is usually retrieved- via the Subscription table. See the DirectMessageGroup model for+ which is the ID of the Stream/DirectMessageGroup object containing+ all the metadata for the audience. There are 2 recipient types:++ 1. Stream message: The type_id is the ID of the associated Stream.+ 2. Direct message: The type_id is the ID of the associated+ DirectMessageGroup object, which encodes the set of users in+ the conversation. The set of users is usually retrieved via the+ Subscription table. See the DirectMessageGroup model fordetails.See also the Subscription model, which stores which UserProfile@@ -43,13 +38,11 @@ class Recipient(models.Model):id = models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name="ID")type_id = models.IntegerField(db_index=True)type = models.PositiveSmallIntegerField(db_index=True)- # Valid types are {personal, stream, direct_message_group}+ # Valid types are {stream, direct_message_group}- # The type for 1:1 direct messages.- PERSONAL = 1# The type for stream messages.STREAM = 2- # The type group direct messages.+ # The type for direct messages (both 1:1 and group).DIRECT_MESSAGE_GROUP = 3class Meta:diff --git a/zerver/models/users.py b/zerver/models/users.pyindex 0163e3a5f0a..4ecf00606a9 100644--- a/zerver/models/users.py+++ b/zerver/models/users.py@@ -510,8 +510,6 @@ class UserProfile(AbstractBaseUser, PermissionsMixin, UserBaseSettings):email = models.EmailField(blank=False, db_index=True)realm = models.ForeignKey("zerver.Realm", on_delete=CASCADE)- # Foreign key to the Recipient object for PERSONAL type messages to this user.- recipient = models.ForeignKey("zerver.Recipient", null=True, on_delete=models.SET_NULL)INACCESSIBLE_USER_NAME = gettext_lazy("Unknown user")# The user's name. We prefer the model of a full_name@@ -1018,7 +1016,6 @@ def base_get_user_narrow_queryset() -> QuerySet[UserProfile]:"presence_enabled","rate_limits","role",- "recipient_id","realm__string_id","realm__deactivated",)diff --git a/zerver/tests/test_handle_push_notification.py b/zerver/tests/test_handle_push_notification.pyindex dc8846b221b..e854044b9e6 100644--- a/zerver/tests/test_handle_push_notification.py+++ b/zerver/tests/test_handle_push_notification.py@@ -61,8 +61,8 @@ class HandlePushNotificationTest(PushNotificationTestCase):self.setup_fcm_tokens()message = self.get_message(- Recipient.PERSONAL,- type_id=self.dm_recipient_user.id,+ Recipient.DIRECT_MESSAGE_GROUP,+ type_id=self.dm_group.id,realm_id=self.dm_recipient_user.realm_id,)UserMessage.objects.create(@@ -162,8 +162,8 @@ class HandlePushNotificationTest(PushNotificationTestCase):realm.save()message = self.get_message(- Recipient.PERSONAL,- type_id=self.dm_recipient_user.id,+ Recipient.DIRECT_MESSAGE_GROUP,+ type_id=self.dm_group.id,realm_id=self.dm_recipient_user.realm_id,)UserMessage.objects.create(@@ -229,8 +229,8 @@ class HandlePushNotificationTest(PushNotificationTestCase):self.setup_fcm_tokens()message = self.get_message(- Recipient.PERSONAL,- type_id=self.dm_recipient_user.id,+ Recipient.DIRECT_MESSAGE_GROUP,+ type_id=self.dm_group.id,realm_id=self.dm_recipient_user.realm_id,)UserMessage.objects.create(@@ -332,8 +332,8 @@ class HandlePushNotificationTest(PushNotificationTestCase):self.setup_fcm_tokens()message = self.get_message(- Recipient.PERSONAL,- type_id=self.dm_recipient_user.id,+ Recipient.DIRECT_MESSAGE_GROUP,+ type_id=self.dm_group.id,realm_id=self.dm_recipient_user.realm_id,)UserMessage.objects.create(@@ -360,8 +360,8 @@ class HandlePushNotificationTest(PushNotificationTestCase):user_profile = self.example_user("hamlet")message = self.get_message(- Recipient.PERSONAL,- type_id=self.dm_recipient_user.id,+ Recipient.DIRECT_MESSAGE_GROUP,+ type_id=self.dm_group.id,realm_id=self.dm_recipient_user.realm_id,)@@ -407,8 +407,8 @@ class HandlePushNotificationTest(PushNotificationTestCase):"""Simulates the race where message is deleted before handling push notifications"""user_profile = self.example_user("hamlet")message = self.get_message(- Recipient.PERSONAL,- type_id=self.dm_recipient_user.id,+ Recipient.DIRECT_MESSAGE_GROUP,+ type_id=self.dm_group.id,realm_id=self.dm_recipient_user.realm_id,)UserMessage.objects.create(@@ -442,8 +442,8 @@ class HandlePushNotificationTest(PushNotificationTestCase):"""Simulates the race where message is missing when handling push notifications"""user_profile = self.example_user("hamlet")message = self.get_message(- Recipient.PERSONAL,- type_id=self.dm_recipient_user.id,+ Recipient.DIRECT_MESSAGE_GROUP,+ type_id=self.dm_group.id,realm_id=self.dm_recipient_user.realm_id,)UserMessage.objects.create(@@ -528,8 +528,8 @@ class HandlePushNotificationTest(PushNotificationTestCase):user_profile = self.user_profilemessage = self.get_message(- Recipient.PERSONAL,- type_id=self.dm_recipient_user.id,+ Recipient.DIRECT_MESSAGE_GROUP,+ type_id=self.dm_group.id,realm_id=self.dm_recipient_user.realm_id,)UserMessage.objects.create(@@ -661,16 +661,15 @@ class HandlePushNotificationTest(PushNotificationTestCase):# * 1 : update fetched user_message flag# * 3 : fetch PushDeviceToken, update RealmCount, fetch Devicemessage = self.get_message(- Recipient.PERSONAL,- type_id=self.dm_recipient_user.id,+ Recipient.DIRECT_MESSAGE_GROUP,+ type_id=self.dm_group.id,realm_id=realm.id,)UserMessage.objects.create(user_profile=self.user_profile, message=message)missed_message = {"message_id": message.id, "trigger": NotificationTriggers.DIRECT_MESSAGE}- test_end_to_end(missed_message, db_query_count=7)+ test_end_to_end(missed_message, db_query_count=8)# Group DM- # 1 extra query than prev for `get_display_recipient` in `get_message_payload`.# Note: We've caching to avoid this query.group_dm = get_or_create_direct_message_group(id_list=[self.user_profile.id, iago.id, zoe.id]@@ -715,8 +714,8 @@ class HandlePushNotificationTest(PushNotificationTestCase):user_profile = self.user_profilemessage = self.get_message(- Recipient.PERSONAL,- type_id=self.dm_recipient_user.id,+ Recipient.DIRECT_MESSAGE_GROUP,+ type_id=self.dm_group.id,realm_id=self.dm_recipient_user.realm_id,)UserMessage.objects.create(@@ -774,8 +773,8 @@ class HandlePushNotificationTest(PushNotificationTestCase):self.setup_apns_tokens()self.setup_fcm_tokens()message = self.get_message(- Recipient.PERSONAL,- type_id=self.dm_recipient_user.id,+ Recipient.DIRECT_MESSAGE_GROUP,+ type_id=self.dm_group.id,realm_id=self.dm_recipient_user.realm_id,)UserMessage.objects.create(@@ -1126,8 +1125,8 @@ class HandlePushNotificationTest(PushNotificationTestCase):) -> None:user_profile = self.example_user("hamlet")message = self.get_message(- Recipient.PERSONAL,- type_id=self.dm_recipient_user.id,+ Recipient.DIRECT_MESSAGE_GROUP,+ type_id=self.dm_group.id,realm_id=self.dm_recipient_user.realm_id,)UserMessage.objects.create(diff --git a/zerver/tests/test_import_export.py b/zerver/tests/test_import_export.pyindex 6d2cac64ecb..c110dc9e847 100644--- a/zerver/tests/test_import_export.py+++ b/zerver/tests/test_import_export.py@@ -1015,12 +1015,6 @@ class RealmImportExportTest(ExportFile):self.assertEqual(get_consented_user_ids(realm), consented_user_ids)- # Remove the recipient of the welcome bot to test exporting bots without it.- internal_realm = get_realm(settings.SYSTEM_BOT_REALM)- welcome_bot = get_system_bot(settings.WELCOME_BOT, internal_realm.id)- welcome_bot.recipient = None- welcome_bot.save(update_fields=["recipient"])-self.export_realm_and_create_auditlog(realm,export_type=RealmExport.EXPORT_FULL_WITH_CONSENT,@@ -1937,8 +1931,7 @@ class RealmImportExportTest(ExportFile):imported_message_with_thumbnail.rendered_content, expected_rendered_preview)- imported_prospero_user = get_user_by_delivery_email(prospero_email, imported_realm)- self.assertIsNone(imported_prospero_user.recipient)+ get_user_by_delivery_email(prospero_email, imported_realm)# Ensure RealmExport.export_path is excluded from the export and thus None after importing.exported_realm_exports = read_json("realm.json")["zerver_realmexport"]diff --git a/zerver/tests/test_mattermost_importer.py b/zerver/tests/test_mattermost_importer.pyindex 7244a6dfedc..9c56411f404 100644--- a/zerver/tests/test_mattermost_importer.py+++ b/zerver/tests/test_mattermost_importer.py@@ -1299,11 +1299,6 @@ class MatterMostImporter(MattermostImportTestBase):)self.assertEqual(group_direct_messages[1].topic_name(), Message.DM_TOPIC)- personal_messages = messages.filter(recipient__type=Recipient.PERSONAL).order_by(- "date_sent"- )- self.assert_length(personal_messages, 0)-def test_do_convert_data_with_masking(self) -> None:mattermost_data_dir = self.fixture_file_name("", "mattermost_fixtures")output_dir = self.make_import_output_dir("mattermost")diff --git a/zerver/tests/test_message_fetch.py b/zerver/tests/test_message_fetch.pyindex 481804eed3b..6be009a162f 100644--- a/zerver/tests/test_message_fetch.py+++ b/zerver/tests/test_message_fetch.py@@ -650,11 +650,6 @@ class NarrowBuilderTest(ZulipTestCase):self._do_add_term_test(term, "WHERE (flags & %(flags_1)s) != %(param_1)s")def test_add_term_using_dm_including_operator_with_different_user_email(self) -> None:- # Simulate a user with recipient=None- othello = self.example_user("othello")- othello.recipient = None- othello.save()-# Test without any such group direct messages existingterm = NarrowParameter(operator="dm-including", operand=self.othello_email)self._do_add_term_test(@@ -676,11 +671,6 @@ class NarrowBuilderTest(ZulipTestCase):def test_add_term_using_dm_including_operator_with_different_user_email_and_negated(self,) -> None: # NEGATED- # Simulate a user with recipient=None- othello = self.example_user("othello")- othello.recipient = None- othello.save()-term = NarrowParameter(operator="dm-including", operand=self.othello_email, negated=True)self._do_add_term_test(term,@@ -5264,7 +5254,7 @@ WHERE zerver_subscription.user_profile_id = {hamlet_id} AND zerver_subscription.)def test_get_messages_with_narrow_queries(self) -> None:- # The query includes both PERSONAL and DM group recipients+ # The query includes DM group recipientsquery_ids = self.get_query_ids()hamlet_email = self.example_user("hamlet").emailothello_email = self.example_user("othello").emaildiff --git a/zerver/tests/test_message_send.py b/zerver/tests/test_message_send.pyindex 73550a859a3..1184d45d370 100644--- a/zerver/tests/test_message_send.py+++ b/zerver/tests/test_message_send.py@@ -2668,8 +2668,6 @@ class StreamMessagesTest(ZulipTestCase):def test_get_raw_unread_data_for_1_to_1_dms_using_group_direct_message(self) -> None:sender = self.example_user("hamlet")receiver = self.example_user("cordelia")- receiver.recipient = None- receiver.save()message1_id = self.send_personal_message(sender, receiver, "test content 1")message2_id = self.send_personal_message(sender, receiver, "test content 2")@@ -2804,10 +2802,6 @@ class PersonalMessageSendTest(ZulipTestCase):sender = self.example_user("hamlet")receiver = self.example_user("othello")- # Remove the existing DM group to test the creation path.- receiver.recipient = None- receiver.save()-self.login("hamlet")self.assert_personal(sender=sender,diff --git a/zerver/tests/test_microsoft_teams_importer.py b/zerver/tests/test_microsoft_teams_importer.pyindex a9f9c96bb0c..a8d1739409b 100644--- a/zerver/tests/test_microsoft_teams_importer.py+++ b/zerver/tests/test_microsoft_teams_importer.py@@ -35,7 +35,6 @@ from zerver.lib.test_classes import ZulipTestCasefrom zerver.lib.topic import messages_for_topicfrom zerver.models.messages import Messagefrom zerver.models.realms import Realm, get_realm-from zerver.models.recipients import Recipientfrom zerver.models.streams import Stream, Subscriptionfrom zerver.models.users import UserProfile, get_system_botfrom zerver.tests.test_import_export import make_export_output_dir@@ -542,30 +541,6 @@ class MicrosoftTeamsImporterUnitTest(MicrosoftTeamsImportTestCase):str(e.exception),)- def test_at_least_one_recipient_per_user(self) -> None:- """- Make sure each user at least has a recipient field. This makes sure the- the onboarding messages, runs smoothly even for users without any- personal messages.- """- realm: dict[str, Any] = {}- realm["zerver_stream"] = []- realm["zerver_defaultstream"] = []- realm["zerver_recipient"] = []- realm["zerver_subscription"] = []- with self.assertLogs(level="INFO"):- microsoft_teams_user_id_to_zulip_user_id = self.convert_users_handler(- realm=realm, microsoft_teams_user_role_data=MICROSOFT_TEAMS_EXPORT_USER_ROLE_DATA- )-- self.assert_length(- realm["zerver_recipient"], len(self.get_exported_microsoft_teams_user_data())- )- zulip_user_ids = set(microsoft_teams_user_id_to_zulip_user_id.values())- for recipient in realm["zerver_recipient"]:- self.assertTrue(recipient["type_id"] in zulip_user_ids)- self.assertTrue(recipient["type"] == Recipient.PERSONAL)-@responses.activatedef test_failed_get_microsoft_graph_api_data(self) -> None:responses.add(diff --git a/zerver/tests/test_outgoing_webhook_system.py b/zerver/tests/test_outgoing_webhook_system.pyindex d34da73af26..f1425b19362 100644--- a/zerver/tests/test_outgoing_webhook_system.py+++ b/zerver/tests/test_outgoing_webhook_system.py@@ -56,7 +56,6 @@ class DoRestCallTests(ZulipTestCase):"stream_id": 999,"recipient_id": 1111,"sender_id": bot_user.id,- "sender_recipient_id": bot_user.recipient_id,"sender_email": bot_user.email,"sender_realm_id": bot_user.realm.id,"sender_realm_str": bot_user.realm.string_id,diff --git a/zerver/tests/test_service_bot_system.py b/zerver/tests/test_service_bot_system.pyindex 3f845088772..d4c618d0b7d 100644--- a/zerver/tests/test_service_bot_system.py+++ b/zerver/tests/test_service_bot_system.py@@ -56,7 +56,7 @@ class TestServiceBotBasics(ZulipTestCase):],active_user_ids={outgoing_bot.id},mentioned_user_ids=set(),- recipient_type=Recipient.PERSONAL,+ recipient_type=Recipient.DIRECT_MESSAGE_GROUP,)expected = dict(@@ -140,7 +140,7 @@ class TestServiceBotBasics(ZulipTestCase):],active_user_ids=set(),mentioned_user_ids={outgoing_bot.id},- recipient_type=Recipient.PERSONAL,+ recipient_type=Recipient.DIRECT_MESSAGE_GROUP,)self.assert_length(event_dict, 0)@@ -165,7 +165,7 @@ class TestServiceBotBasics(ZulipTestCase):],active_user_ids=set(),mentioned_user_ids={bot.id},- recipient_type=Recipient.PERSONAL,+ recipient_type=Recipient.DIRECT_MESSAGE_GROUP,)self.assert_length(event_dict, 0)diff --git a/zerver/tests/test_slack_importer.py b/zerver/tests/test_slack_importer.pyindex b5497b6e674..c820ae3abd1 100644--- a/zerver/tests/test_slack_importer.py+++ b/zerver/tests/test_slack_importer.py@@ -28,8 +28,6 @@ from zerver.data_import.import_util import (UploadRecordData,ZerverFieldsT,build_defaultstream,- build_recipient,- build_subscription,build_usermessages,build_zerver_realm,download_and_export_upload_file,@@ -69,14 +67,7 @@ from zerver.lib.test_classes import ZulipTestCasefrom zerver.lib.test_helpers import find_key_by_email, read_test_image_filefrom zerver.lib.thumbnail import THUMBNAIL_ACCEPT_IMAGE_TYPES, BadImageErrorfrom zerver.lib.topic import EXPORT_TOPIC_NAME-from zerver.models import (- Message,- PreregistrationRealm,- Realm,- RealmAuditLog,- Recipient,- UserProfile,-)+from zerver.models import Message, PreregistrationRealm, Realm, RealmAuditLog, UserProfilefrom zerver.models.realm_audit_logs import AuditLogEventTypefrom zerver.models.realms import get_realm@@ -955,23 +946,6 @@ class SlackImporter(ZulipTestCase):test_default_channel = {"stream": 1, "realm": 1, "id": 1}self.assertDictEqual(test_default_channel, default_channel_general)- def test_build_pm_recipient_sub_from_user(self) -> None:- zulip_user_id = 3- recipient_id = 5- subscription_id = 7- sub = build_subscription(recipient_id, zulip_user_id, subscription_id)- recipient = build_recipient(zulip_user_id, recipient_id, Recipient.PERSONAL)-- self.assertEqual(recipient["id"], sub["recipient"])- self.assertEqual(recipient["type_id"], sub["user_profile"])-- self.assertEqual(recipient["type"], Recipient.PERSONAL)- self.assertEqual(recipient["type_id"], 3)-- self.assertEqual(sub["recipient"], 5)- self.assertEqual(sub["id"], 7)- self.assertEqual(sub["active"], True)-def test_build_subscription(self) -> None:channel_members = ["U061A1R2R", "U061A3E0G", "U061A5N1G", "U064KUGRJ"]slack_user_id_to_zulip_user_id = {diff --git a/zerver/tests/test_subs.py b/zerver/tests/test_subs.pyindex 6bb98ac045d..c938d339902 100644--- a/zerver/tests/test_subs.py+++ b/zerver/tests/test_subs.py@@ -5421,7 +5421,7 @@ class SubscriptionAPITest(ZulipTestCase):notification_bot_dms = Message.objects.filter(realm_id=realm.id,sender=bot.id,- recipient__type=Recipient.PERSONAL,+ recipient__type=Recipient.DIRECT_MESSAGE_GROUP,date_sent__gt=now,)self.assertEqual(notification_bot_dms.count(), 0)@@ -5474,7 +5474,7 @@ class SubscriptionAPITest(ZulipTestCase):notification_bot_dms = Message.objects.filter(realm_id=realm.id,sender=bot.id,- recipient__type=Recipient.PERSONAL,+ recipient__type=Recipient.DIRECT_MESSAGE_GROUP,date_sent__gt=now,)self.assertEqual(notification_bot_dms.count(), 0)@@ -5505,7 +5505,7 @@ class SubscriptionAPITest(ZulipTestCase):notification_bot_dms = Message.objects.filter(realm_id=realm.id,sender=bot.id,- recipient__type=Recipient.PERSONAL,+ recipient__type=Recipient.DIRECT_MESSAGE_GROUP,date_sent__gt=now,)self.assertEqual(notification_bot_dms.count(), 0)diff --git a/zerver/tests/test_users.py b/zerver/tests/test_users.pyindex 018b15a2643..bc85890af12 100644--- a/zerver/tests/test_users.py+++ b/zerver/tests/test_users.py@@ -648,8 +648,6 @@ class PermissionTest(ZulipTestCase):def test_access_user_by_id_with_null_recipient(self) -> None:self.set_up_db_for_testing_user_access()polonius = self.example_user("polonius")- polonius.recipient = None- polonius.save()# Restricting the "Members" system group to not allow access to all users.realm = get_realm("zulip")@@ -1472,8 +1470,6 @@ class AdminCreateUserTest(ZulipTestCase):# Make sure the new user got the realm's default languageself.assertEqual(new_user.default_language, "ja")- self.assertIsNone(new_user.recipient)-# we can't create the same user twice.result = self.client_post("/json/users", valid_params)self.assert_json_error(result, "Email is already in use.")@@ -3759,8 +3755,6 @@ class GetProfileTest(ZulipTestCase):def test_get_inaccessible_user_ids_with_null_recipient(self) -> None:polonius = self.example_user("polonius")- polonius.recipient = None- polonius.save()bot = self.example_user("default_bot")hamlet = self.example_user("hamlet")