-
-
Notifications
You must be signed in to change notification settings - Fork 6.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
384f3a0
commit fa8322d
Showing
2 changed files
with
29 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,7 +14,7 @@ class Meta: | |
|
||
|
||
class UserUpdate(generics.UpdateAPIView): | ||
queryset = User.objects.all().prefetch_related('groups') | ||
queryset = User.objects.exclude(username='exclude').prefetch_related('groups') | ||
serializer_class = UserSerializer | ||
|
||
|
||
|
@@ -39,3 +39,21 @@ def test_prefetch_related_updates(self): | |
'email': '[email protected]' | ||
} | ||
assert response.data == expected | ||
|
||
def test_prefetch_related_excluding_instance_from_original_queryset(self): | ||
""" | ||
Regression test for https://github.com/tomchristie/django-rest-framework/issues/4661 | ||
""" | ||
view = UserUpdate.as_view() | ||
pk = self.user.pk | ||
groups_pk = self.groups[0].pk | ||
request = factory.put('/', {'username': 'exclude', 'groups': [groups_pk]}, format='json') | ||
response = view(request, pk=pk) | ||
assert User.objects.get(pk=pk).groups.count() == 1 | ||
expected = { | ||
'id': pk, | ||
'username': 'exclude', | ||
'groups': [1], | ||
'email': '[email protected]' | ||
} | ||
assert response.data == expected |