diff options
| author | Ian Foote <python@ian.feete.org> | 2015-11-07 16:06:06 +0100 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2015-12-17 19:08:30 -0500 |
| commit | 86eccdc8b67728d84440a46e5bf62c78f2eddf6d (patch) | |
| tree | 6433cbf59d1f4a5ae9aa6b5b5809ee933bac7f65 /tests | |
| parent | ed1bcf05158acf4bf4e0189d477b6c762bd0133e (diff) | |
Fixed #25544 -- Removed duplicate ids in prefetch_related() queries.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/postgres_tests/test_hstore.py | 8 | ||||
| -rw-r--r-- | tests/prefetch_related/tests.py | 22 |
2 files changed, 30 insertions, 0 deletions
diff --git a/tests/postgres_tests/test_hstore.py b/tests/postgres_tests/test_hstore.py index 68c54918a1..80e46e5021 100644 --- a/tests/postgres_tests/test_hstore.py +++ b/tests/postgres_tests/test_hstore.py @@ -67,6 +67,14 @@ class TestQuerying(PostgreSQLTestCase): self.objs[:2] ) + def test_in_generator(self): + def search(): + yield {'a': 'b'} + self.assertSequenceEqual( + HStoreModel.objects.filter(field__in=search()), + self.objs[:1] + ) + def test_has_key(self): self.assertSequenceEqual( HStoreModel.objects.filter(field__has_key='c'), diff --git a/tests/prefetch_related/tests.py b/tests/prefetch_related/tests.py index 56bd64b5b9..01c64b0959 100644 --- a/tests/prefetch_related/tests.py +++ b/tests/prefetch_related/tests.py @@ -6,6 +6,7 @@ from django.db import connection from django.db.models import Prefetch from django.db.models.query import get_prefetcher from django.test import TestCase, override_settings +from django.test.utils import CaptureQueriesContext from django.utils import six from django.utils.encoding import force_text @@ -245,6 +246,27 @@ class PrefetchRelatedTests(TestCase): # save of reverse relation assignment. self.assertEqual(self.author1.books.count(), 2) + def test_m2m_then_reverse_fk_object_ids(self): + with CaptureQueriesContext(connection) as queries: + list(Book.objects.prefetch_related('authors__addresses')) + + sql = queries[-1]['sql'] + self.assertEqual(sql.count(self.author1.name), 1) + + def test_m2m_then_m2m_object_ids(self): + with CaptureQueriesContext(connection) as queries: + list(Book.objects.prefetch_related('authors__favorite_authors')) + + sql = queries[-1]['sql'] + self.assertEqual(sql.count(self.author1.name), 1) + + def test_m2m_then_reverse_one_to_one_object_ids(self): + with CaptureQueriesContext(connection) as queries: + list(Book.objects.prefetch_related('authors__authorwithage')) + + sql = queries[-1]['sql'] + self.assertEqual(sql.count(str(self.author1.id)), 1, sql) + class CustomPrefetchTests(TestCase): @classmethod |
