Skip to content
Snippets Groups Projects
Commit 685532a5 authored by Valentin Rigal's avatar Valentin Rigal Committed by Bastien Abadie
Browse files

Avoid a stale read listing generic memberships

parent d102f52c
No related branches found
No related tags found
1 merge request!1183Avoid a stale read listing generic memberships
......@@ -668,7 +668,8 @@ class GenericMembershipsList(ACLMixin, ListAPIView):
except (AttributeError, ValueError):
raise ValidationError({key: [f"'{content_id}' is not a valid UUID."]})
return get_object_or_404(self.content_object_params[key], id=content_uuid)
# Use default database in case the content object has just been created
return get_object_or_404(self.content_object_params[key].objects.using('default'), id=content_uuid)
def get_queryset(self):
content_object = self.get_content_object()
......@@ -680,7 +681,9 @@ class GenericMembershipsList(ACLMixin, ListAPIView):
if not self.has_access(content_object, Role.Guest.value, **access_params):
raise PermissionDenied(detail='You do not have the required access level to list members for this content.')
# Avoid a stale read when adding/deletig a member
qs = content_object.memberships \
.using('default') \
.prefetch_related(
'user',
Prefetch('group', queryset=Group.objects.annotate(members_count=Count('memberships')))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment