Opened 8 years ago

Closed 8 years ago

#14104 closed (wontfix)

Allow joined field in F()s

Reported by: Evandro Myller Owned by: nobody
Component: Database layer (models, ORM) Version: master
Severity: Keywords:
Cc: evandromyller@… Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


I have a ( A 1:n B 1:n C ) schema and I query for the A's pk from C objects very often. To shorten the query, I want to make a foreign key to A in C, so I don't need to join anymore.

In order to achieve that, I put the following code in a migration script:


...but I get the following when I try to run it:

File "/usr/local/lib/python2.6/dist-packages/django/db/models/sql/", line 835, in as_sql

val = SQLEvaluator(val, self.query, allow_joins=False)

File "/usr/local/lib/python2.6/dist-packages/django/db/models/sql/", line 12, in init

self.expression.prepare(self, query, allow_joins)

File "/usr/local/lib/python2.6/dist-packages/django/db/models/", line 110, in prepare

return evaluator.prepare_leaf(self, query, allow_joins)

File "/usr/local/lib/python2.6/dist-packages/django/db/models/sql/", line 35, in prepare_leaf

raise FieldError("Joined field references are not permitted in this query")

django.core.exceptions.FieldError: Joined field references are not permitted in this query

(Full traceback attached)

Attachments (1)

traceback (3.2 KB) - added by Evandro Myller 8 years ago.
full traceback

Download all attachments as: .zip

Change History (2)

Changed 8 years ago by Evandro Myller

Attachment: traceback added

full traceback

comment:1 Changed 8 years ago by Russell Keith-Magee

Resolution: wontfix
Status: newclosed

The actual issue here appears to be that joined F() clauses aren't permitted in update() statements. This is by design; support for joins in update() clauses was explicitly removed due to inherent complications in supporting them in the general case.

I'm happy to reopen this if it comes with a complete patch that solves all the inherent problems, but otherwise, I'm closing wontfix.

Note: See TracTickets for help on using tickets.
Back to Top