Skip to content

Commit

Permalink
user_groups: Work around django-cte bug with Django 4.2.
Browse files Browse the repository at this point in the history
dimagi/django-cte#66

Signed-off-by: Anders Kaseorg <[email protected]>
  • Loading branch information
andersk authored and bigBrain1901 committed Apr 12, 2023
1 parent 9009407 commit dc7a823
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions zerver/lib/user_groups.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from typing import Dict, Iterable, List, Sequence, TypedDict

from django.db.models import QuerySet
from django.db.models import F, QuerySet
from django.utils.translation import gettext as _
from django_cte import With
from django_stubs_ext import ValuesQuerySet
Expand Down Expand Up @@ -157,10 +157,10 @@ def get_direct_memberships_of_users(user_group: UserGroup, members: List[UserPro
def get_recursive_subgroups(user_group: UserGroup) -> QuerySet[UserGroup]:
cte = With.recursive(
lambda cte: UserGroup.objects.filter(id=user_group.id)
.values("id")
.union(cte.join(UserGroup, direct_supergroups=cte.col.id).values("id"))
.values(group_id=F("id"))
.union(cte.join(UserGroup, direct_supergroups=cte.col.group_id).values(group_id=F("id")))
)
return cte.join(UserGroup, id=cte.col.id).with_cte(cte)
return cte.join(UserGroup, id=cte.col.group_id).with_cte(cte)


def get_recursive_group_members(user_group: UserGroup) -> QuerySet[UserProfile]:
Expand All @@ -169,11 +169,11 @@ def get_recursive_group_members(user_group: UserGroup) -> QuerySet[UserProfile]:

def get_recursive_membership_groups(user_profile: UserProfile) -> QuerySet[UserGroup]:
cte = With.recursive(
lambda cte: user_profile.direct_groups.values("id").union(
cte.join(UserGroup, direct_subgroups=cte.col.id).values("id")
lambda cte: user_profile.direct_groups.values(group_id=F("id")).union(
cte.join(UserGroup, direct_subgroups=cte.col.group_id).values(group_id=F("id"))
)
)
return cte.join(UserGroup, id=cte.col.id).with_cte(cte)
return cte.join(UserGroup, id=cte.col.group_id).with_cte(cte)


def is_user_in_group(
Expand Down

0 comments on commit dc7a823

Please sign in to comment.