Opened 10 years ago

Closed 10 years ago

#3740 closed (duplicate)

Django creates wrong query for postgresql 8.1

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


I'm getting a programming error 'missing FROM-clause entry for table "mail_domain"'. The query that django constructed was:

'SELECT "mail_alias"."id","mail_alias"."address","mail_alias"."domain_id","mail_alias"."enabled" FROM "mail_alias" ORDER BY "mail_domain"."name" ASC'

which works when I add mail_domain to the from-clause as

'SELECT "mail_alias"."id","mail_alias"."address","mail_alias"."domain_id","mail_alias"."enabled" FROM "mail_alias", "mail_domain" ORDER BY "mail_domain"."name" ASC'

The model for Alias which triggers the bug is attached. I'm using the current (r4739) trunk.

Attachments (1) (560 bytes) - added by anonymous 10 years ago.
contains only the "Alias"-model which triggers the bug

Download all attachments as: .zip

Change History (3)

Changed 10 years ago by anonymous

Attachment: added

contains only the "Alias"-model which triggers the bug

comment:1 Changed 10 years ago by me@…

Needs documentation: unset
Needs tests: unset
Patch needs improvement: unset

This occures with both postgresql-backends. It seems to be caused by Alias' str-method (see attached file).

if class Admin contains

list_display = ('__str__', 'enabled')

it fails, because str is built from both and if it contains

list_display = ('__str__', 'domain', 'enabled')

it works, because "domain" is explicitly included.

comment:2 Changed 10 years ago by James Bennett

Resolution: duplicate
Status: newclosed

I strongly suspect that this is a duplicate of #2076, since the buggy behavior -- Django fails to add a related table name to the SELECT clause -- is identical. Closing as a dupe for now, but if this turns out not to be the same bug it should be reopened.

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