Code

Ticket #6804: hack.diff

File hack.diff, 933 bytes (added by floguy, 6 years ago)

This does special case checking to see if it's a RelatedObject and if so, doesn't raise a JoinError. This causes one test to break, and that's because I don't understand the implications of the change that was made. Maybe this hack can be expanded upon to get a real solution. (Using patch #6095)

Line 
1Index: django/db/models/sql/query.py
2===================================================================
3--- django/db/models/sql/query.py       (revision 7274)
4+++ django/db/models/sql/query.py       (working copy)
5@@ -20,6 +20,7 @@
6 from django.core.exceptions import FieldError
7 from datastructures import EmptyResultSet, Empty, JoinError
8 from constants import *
9+from django.db.models.related import RelatedObject
10 
11 try:
12     set
13@@ -1004,7 +1005,7 @@
14                     names = opts.get_all_field_names()
15                     raise FieldError("Cannot resolve keyword %r into field. "
16                             "Choices are: %s" % (name, ", ".join(names)))
17-            if not allow_many and (m2m or not direct):
18+            if not allow_many and (m2m or not direct) and not isinstance(field, RelatedObject):
19                 for alias in joins:
20                     self.unref_alias(alias)
21                 raise JoinError(pos + 1)