diff options
| author | Malcolm Tredinnick <malcolm.tredinnick@gmail.com> | 2009-03-08 03:32:16 +0000 |
|---|---|---|
| committer | Malcolm Tredinnick <malcolm.tredinnick@gmail.com> | 2009-03-08 03:32:16 +0000 |
| commit | cd99c62e2de8701ffd940d86da8e41798c10007d (patch) | |
| tree | b6ac74ce1b2951aff49e7c5ddd0a4968f788bf12 /tests/regressiontests | |
| parent | f1ada99997de72fdd3f765ffa11fa4d1d9f438f9 (diff) | |
Fixed #10432 -- Handle all kinds of iterators in queryset filters.
Only consumes the iterators once and works with Python 2.3.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@9986 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'tests/regressiontests')
| -rw-r--r-- | tests/regressiontests/queries/models.py | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/tests/regressiontests/queries/models.py b/tests/regressiontests/queries/models.py index 727a537e43..ccf06be5f3 100644 --- a/tests/regressiontests/queries/models.py +++ b/tests/regressiontests/queries/models.py @@ -1090,6 +1090,19 @@ to set things up correctly internally so that subqueries can continue properly. >>> Tag.objects.filter(name__in=()).update(name="foo") 0 +Bug #10432 (see also the Python 2.4+ tests for this, below). Testing an empty +"__in" filter with a generator as the value. +>>> def f(): +... return iter([]) +>>> n_obj = Note.objects.all()[0] +>>> def g(): +... for i in [n_obj.pk]: +... yield i +>>> Note.objects.filter(pk__in=f()) +[] +>>> list(Note.objects.filter(pk__in=g())) == [n_obj] +True + """} # In Python 2.3 and the Python 2.6 beta releases, exceptions raised in __len__ @@ -1140,3 +1153,13 @@ True True """ + +# Generator expressions are only in Python 2.4 and later. +if sys.version_info >= (2, 4): + __test__["API_TESTS"] += """ +Using an empty generator expression as the rvalue for an "__in" lookup is legal +(regression for #10432). +>>> Note.objects.filter(pk__in=(x for x in ())) +[] + +""" |
