diff --git a/arkindex/users/api.py b/arkindex/users/api.py index b97e9d2144541c57da440e9cf52dbe8777967f60..cd66a9b7abc7aae27f0f672b01832743fee73cd1 100644 --- a/arkindex/users/api.py +++ b/arkindex/users/api.py @@ -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')))