Opened 14 years ago

Closed 13 years ago

#14104 closed (wontfix)

Allow joined field in F()s

Reported by: Evandro Myller Owned by: nobody
Component: Database layer (models, ORM) Version: dev
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

Description

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:

C.objects.update(a=F('ba'))

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

File "/usr/local/lib/python2.6/dist-packages/django/db/models/sql/compiler.py", 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/expressions.py", line 12, in init

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

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

return evaluator.prepare_leaf(self, query, allow_joins)

File "/usr/local/lib/python2.6/dist-packages/django/db/models/sql/expressions.py", 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 14 years ago.
full traceback

Download all attachments as: .zip

Change History (2)

by Evandro Myller, 14 years ago

Attachment: traceback added

full traceback

comment:1 by Russell Keith-Magee, 13 years ago

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