Fix: type casting of db values for shared by me filter (#5155)

This commit is contained in:
shamoon 2023-12-29 09:19:45 -08:00 committed by GitHub
parent 05e294fc81
commit cf869b1356
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,7 +1,9 @@
from django.contrib.contenttypes.models import ContentType
from django.db.models import CharField
from django.db.models import Count
from django.db.models import OuterRef
from django.db.models import Q
from django.db.models.functions import Cast
from django_filters.rest_framework import BooleanFilter
from django_filters.rest_framework import Filter
from django_filters.rest_framework import FilterSet
@ -119,7 +121,7 @@ class SharedByUser(Filter):
num_shared_users=Count(
UserObjectPermission.objects.filter(
content_type=ctype,
object_pk=OuterRef("pk"),
object_pk=Cast(OuterRef("pk"), CharField()),
).values("user_id"),
),
)
@ -127,7 +129,7 @@ class SharedByUser(Filter):
num_shared_groups=Count(
GroupObjectPermission.objects.filter(
content_type=ctype,
object_pk=OuterRef("pk"),
object_pk=Cast(OuterRef("pk"), CharField()),
).values("group_id"),
),
)