  from django.contrib.auth.models import Group, User
  from django.test import TestCase
  
  from rest_framework import generics, serializers
  from rest_framework.test import APIRequestFactory
  
  factory = APIRequestFactory()
 
</s> remove class UserUpdate(generics.UpdateAPIView):
    queryset = User.objects.exclude(username='exclude').prefetch_related('groups')
 </s> add class UserUpdateWithoutPrefetchRelated(generics.UpdateAPIView):
    queryset = User.objects.exclude(username='exclude') </s> remove         fields = ('id', 'username', 'email', 'groups')
 </s> add         fields = ('id', 'username', 'email', 'groups', 'permissions')


class UserRetrieveUpdate(generics.RetrieveUpdateAPIView):
    queryset = User.objects.exclude(username='exclude').prefetch_related(
        Prefetch('groups', queryset=Group.objects.exclude(name='exclude')),
        'groups__permissions',
    )
    serializer_class = UserSerializer </s> remove         self.groups = [Group.objects.create(name='a'), Group.objects.create(name='b')]
 </s> add         self.groups = [Group.objects.create(name=f'group {i}') for i in range(10)]
from django.db.models.query import Prefetch
  from django.contrib.auth.models import Group, User
from django.db.models.query import Prefetch
  from django.test import TestCase
  
  from rest_framework import generics, serializers
  from rest_framework.test import APIRequestFactory
  
  factory = APIRequestFactory()
add keep keep keep keep keep keep
 Re-prefetch related objects after updating (#8043)

* Re-prefetch related objects after updating

* Fix flake8 format

* Use _prefetch_related_lookups and refine test cases

* Add more test cases and refine prefetch checking 
tests/test_prefetch_related.py