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.

users: Directly access id of foreign keys instead of full object.

Sahil Batrac11cf8eb5417
diff --git a/zerver/actions/create_user.py b/zerver/actions/create_user.py
index cb1f0040522..fffce761168 100644
--- a/zerver/actions/create_user.py
+++ b/zerver/actions/create_user.py
@@ -379,8 +379,8 @@ def created_bot_event(user_profile: UserProfile) -> Dict[str, Any]:
# Set the owner key only when the bot has an owner.
# The default bots don't have an owner. So don't
# set the owner key while reactivating them.
- if user_profile.bot_owner is not None:
- bot["owner_id"] = user_profile.bot_owner.id
+ if user_profile.bot_owner_id is not None:
+ bot["owner_id"] = user_profile.bot_owner_id
return dict(type="realm_bot", op="add", bot=bot)
diff --git a/zerver/lib/addressee.py b/zerver/lib/addressee.py
index 567e021664d..06a786eff8d 100644
--- a/zerver/lib/addressee.py
+++ b/zerver/lib/addressee.py
@@ -118,9 +118,9 @@ class Addressee:
# This is a hack to deal with the fact that we still support
# default streams (and the None will be converted later in the
# call path).
- if sender.default_sending_stream:
+ if sender.default_sending_stream_id:
# Use the user's default stream
- stream_name_or_id = sender.default_sending_stream.id
+ stream_name_or_id = sender.default_sending_stream_id
else:
raise JsonableError(_("Missing stream"))
diff --git a/zerver/models.py b/zerver/models.py
index d93dab4037f..fa3788e043e 100644
--- a/zerver/models.py
+++ b/zerver/models.py
@@ -1990,7 +1990,7 @@ class UserProfile(AbstractBaseUser, PermissionsMixin, UserBaseSettings): # type
def can_admin_user(self, target_user: "UserProfile") -> bool:
"""Returns whether this user has permission to modify target_user"""
- if target_user.bot_owner == self:
+ if target_user.bot_owner_id == self.id:
return True
elif self.is_realm_admin and self.realm == target_user.realm:
return True
diff --git a/zerver/views/streams.py b/zerver/views/streams.py
index 534a70ed70a..948034815dd 100644
--- a/zerver/views/streams.py
+++ b/zerver/views/streams.py
@@ -140,7 +140,7 @@ def user_directly_controls_user(user_profile: UserProfile, target: UserProfile)
owned by the current user"""
if user_profile == target:
return True
- if target.is_bot and target.bot_owner == user_profile:
+ if target.is_bot and target.bot_owner_id == user_profile.id:
return True
return False