Combination of F() expression with query seems to confuse sql compiler's table aliases
|Reported by:||Owned by:||nobody|
|Component:||Database layer (models, ORM)||Version:||1.4|
|Has patch:||no||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
I have a query that causes the sql compiler to output invalid sql. Running a query of the form (excuse the coarse anonymization):
AThroughModel.objects.exclude ( foreignkeyfield_a__m2mfield_b__m2mfield_c = F ( "foreignkeyfield_x__foreignkeyfield_y__foreignkeyfield_z" ) )
this causes an exception along the lines of:
DatabaseError: missing FROM-clause entry for table "u4" LINE 1: ...) INNER JOIN "m2mfield_b_join_table_name" U5 ON (U4."id" = ...
Where AThroughModel is a model that's used as a "through" in an m2mfield from foreignkeyfield_x's model to foreignkeyfield_a's model.
Interestingly, it works when you exchange the .exclude() with a .filter().
This happens both on django 1.3.1 and 1.4.1 with a postgres backend & psycopg2.
Again, sorry about the dumb anonymization, but my boss would be a bit funny about exposing model structure. A full (non) working test case might be a bit tricky as such.
Change History (10)
comment:1 Changed 4 years ago by
|Patch needs improvement:||unset|
|Status:||new → closed|