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.
This commit is contained in:
Sahil Batra 2023-07-12 15:31:52 +05:30 committed by Tim Abbott
parent 62f01edee3
commit 3ae0b4f913
1 changed files with 4 additions and 2 deletions

View File

@ -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")