From 3ae0b4f91387a8c767c107155a87120888d74eba Mon Sep 17 00:00:00 2001 From: Sahil Batra Date: Wed, 12 Jul 2023 15:31:52 +0530 Subject: [PATCH] dev_login: Pass realm as arg to select_related calls. This commit updates the select_related calls in queries to get UserProfile objects in dev_login code to pass "realm" as argument to select_related call. Also, note that "realm" is the only non-null foreign key field in UserProfile object, so select_related() was only fetching realm object previously as well. But we should still pass "realm" as argument in select_related call so that we can make sure that only required fields are selected in case we add more foreign keys to UserProfile in future. --- zerver/views/development/dev_login.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/zerver/views/development/dev_login.py b/zerver/views/development/dev_login.py index 55213dc1bd..38cfa318d8 100644 --- a/zerver/views/development/dev_login.py +++ b/zerver/views/development/dev_login.py @@ -30,11 +30,13 @@ def get_dev_users(realm: Optional[Realm] = None, extra_users_count: int = 10) -> # it still makes sense to limit how many extra users we render to # support performance testing with DevAuthBackend. if realm is not None: - users_query = UserProfile.objects.select_related().filter( + users_query = UserProfile.objects.select_related("realm").filter( is_bot=False, is_active=True, realm=realm ) else: - users_query = UserProfile.objects.select_related().filter(is_bot=False, is_active=True) + users_query = UserProfile.objects.select_related("realm").filter( + is_bot=False, is_active=True + ) shakespearian_users = users_query.exclude(email__startswith="extrauser").order_by("email") extra_users = users_query.filter(email__startswith="extrauser").order_by("email")