Opened 5 years ago

Closed 5 years ago

#14104 closed (wontfix)

Allow joined field in F()s

Reported by: emyller 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: UI/UX:


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 emyller 5 years ago.
full traceback

Download all attachments as: .zip

Change History (2)

Changed 5 years ago by emyller

full traceback

comment:1 Changed 5 years ago by russellm

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Resolution set to wontfix
  • Status changed from new to closed

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