Code

Opened 7 years ago

Closed 7 years ago

#3740 closed (duplicate)

Django creates wrong query for postgresql 8.1

Reported by: me@… Owned by: adrian
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:

Description

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)

models.py (560 bytes) - added by anonymous 7 years ago.
contains only the "Alias"-model which triggers the bug

Download all attachments as: .zip

Change History (3)

Changed 7 years ago by anonymous

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

comment:1 Changed 7 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 self.name and self.domain.name. if it contains

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

it works, because "domain" is explicitly included.

comment:2 Changed 7 years ago by ubernostrum

  • Resolution set to duplicate
  • Status changed from new to closed

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.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.