1
0
mirror of https://github.com/django/django.git synced 2024-12-23 01:25:58 +00:00

Fixed #22992 -- regression in .filter(generic_fk=...) error message

Generic Foreign Keys can't be used as lhs in lookups for historical
reasons. Django 1.6 gave a FieldDoesNotExist exception when using GFKs
as lhs in lookups, but due to regression caused by lookup refactor patch
(20bab2cf9d) the exception type was
changed to AttributeError.

It might be a good idea to add support for gfk__exact and gfk__in lookups
later on.

Thanks to glicerinu@gmail.com for the report. The code in this commit
was written by Tim Graham.
This commit is contained in:
Anssi Kääriäinen 2014-07-14 15:02:00 +03:00 committed by Tim Graham
parent 9cd5201abd
commit efe87d3e48

View File

@ -355,6 +355,10 @@ class GenericRelationsTests(TestCase):
self.assertFalse(created) self.assertFalse(created)
self.assertEqual(tag.content_object.id, diamond.id) self.assertEqual(tag.content_object.id, diamond.id)
def test_query_content_type(self):
with six.assertRaisesRegex(self, FieldError, "^Cannot resolve keyword 'content_object' into field."):
TaggedItem.objects.get(content_object='')
class CustomWidget(forms.TextInput): class CustomWidget(forms.TextInput):
pass pass