| 1359 | self.assertSequenceEqual(Note.objects.exclude(negate=True), [self.n3]) |
| 1360 | |
| 1361 | def test_combining_does_not_mutate(self): |
| 1362 | all_authors = Author.objects.all() |
| 1363 | authors_with_report = Author.objects.filter( |
| 1364 | Exists(Report.objects.filter(creator__pk=OuterRef("id"))) |
| 1365 | ) |
| 1366 | authors_without_report = all_authors.exclude(pk__in=authors_with_report) |
| 1367 | items_before = Item.objects.filter(creator__in=authors_without_report) |
| 1368 | self.assertCountEqual(items_before, [self.i2, self.i3, self.i4]) |
| 1369 | # Combining querysets doesn't mutate them. |
| 1370 | all_authors | authors_with_report |
| 1371 | all_authors & authors_with_report |
| 1372 | |
| 1373 | authors_without_report = all_authors.exclude(pk__in=authors_with_report) |
| 1374 | items_after = Item.objects.filter(creator__in=authors_without_report) |
| 1375 | |
| 1376 | self.assertCountEqual(items_after, [self.i2, self.i3, self.i4]) |
| 1377 | self.assertCountEqual(items_before, items_after) |
| 1378 | |
| 1379 | @skipUnlessDBFeature("supports_select_union") |
| 1380 | def test_union_values_subquery(self): |