summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClaude Paroz <claude@2xlibre.net>2016-08-02 17:27:45 +0200
committerClaude Paroz <claude@2xlibre.net>2016-08-04 16:05:21 +0200
commit272eccf7ff0ced609e5a5e3bb6b4a40e773e0e66 (patch)
tree59689e5a6fd7e68401097ecbfb3f214f7c2ad315
parent7bc5274f6faf9e5296688d4708de0272a758e3f0 (diff)
Fixed #26983 -- Fixed isnull filtering on ForeignKey with to_field
Thanks weidwonder for the report.
-rw-r--r--django/db/models/fields/related_lookups.py2
-rw-r--r--docs/releases/1.10.1.txt3
-rw-r--r--tests/queries/tests.py13
3 files changed, 17 insertions, 1 deletions
diff --git a/django/db/models/fields/related_lookups.py b/django/db/models/fields/related_lookups.py
index 5454031c2a..de2564fb0d 100644
--- a/django/db/models/fields/related_lookups.py
+++ b/django/db/models/fields/related_lookups.py
@@ -93,7 +93,7 @@ class RelatedLookupMixin(object):
# ForeignKey to IntegerField given value 'abc'. The ForeignKey itself
# doesn't have validation for non-integers, so we must run validation
# using the target field.
- if hasattr(self.lhs.output_field, 'get_path_info'):
+ if self.prepare_rhs and hasattr(self.lhs.output_field, 'get_path_info'):
# Get the target field. We can safely assume there is only one
# as we don't get to the direct value branch otherwise.
target_field = self.lhs.output_field.get_path_info()[-1].target_fields[-1]
diff --git a/docs/releases/1.10.1.txt b/docs/releases/1.10.1.txt
index d5bfcac2bd..8f0756bb9e 100644
--- a/docs/releases/1.10.1.txt
+++ b/docs/releases/1.10.1.txt
@@ -26,3 +26,6 @@ Bugfixes
* Fixed a crash if ``request.META['CONTENT_LENGTH']`` is an empty string
(:ticket:`27005`).
+
+* Fixed the ``isnull`` lookup on a ``ForeignKey`` with its ``to_field``
+ pointing to a ``CharField`` (:ticket:`26983`).
diff --git a/tests/queries/tests.py b/tests/queries/tests.py
index e40ab1fa58..fdfd1b5725 100644
--- a/tests/queries/tests.py
+++ b/tests/queries/tests.py
@@ -2483,6 +2483,19 @@ class ToFieldTests(TestCase):
[node1]
)
+ def test_isnull_query(self):
+ apple = Food.objects.create(name="apple")
+ Eaten.objects.create(food=apple, meal="lunch")
+ Eaten.objects.create(meal="lunch")
+ self.assertQuerysetEqual(
+ Eaten.objects.filter(food__isnull=False),
+ ['<Eaten: apple at lunch>']
+ )
+ self.assertQuerysetEqual(
+ Eaten.objects.filter(food__isnull=True),
+ ['<Eaten: None at lunch>']
+ )
+
class ConditionalTests(BaseQuerysetTest):
"""Tests whose execution depend on different environment conditions like