Opened 7 years ago

Closed 13 months ago

#11329 closed Bug (wontfix)

get_count generates incorrect SQL for query sets with extra 'select' and 'where'

Reported by: bogklug Owned by: nobody
Component: Database layer (models, ORM) Version: 1.0
Severity: Normal Keywords: sql, extra select, extra where, get_count
Cc: markus.magnuson@… Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Alex)

Extending an example on extra 'select' from with an extra 'with' and calling get_count:

        'entry_count': 'SELECT COUNT(*) FROM blog_entry WHERE blog_entry.blog_id ='

results in OperationalError: no such column: entry_count.

The SQL for the query itself is ok. It seems that the problem is caused by get_count.

Attachments (1)

sql-get-count-with-select-extra.patch (701 bytes) - added by joaoma@… 7 years ago.
Check for extra_select in get_count

Download all attachments as: .zip

Change History (9)

comment:1 Changed 7 years ago by Alex

  • Description modified (diff)
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

Please use the preview option. Also, are you using the internal get_count() function instead of the public count() API.

Changed 7 years ago by joaoma@…

Check for extra_select in get_count

comment:2 Changed 7 years ago by João Marcus

I am not a Django developer, but this looks like a simple patch. The get_count() function does not check for select causes included with ".extra". Attached my patch.

comment:3 Changed 7 years ago by Alex

  • Triage Stage changed from Unreviewed to Accepted

comment:4 Changed 5 years ago by julien

  • Severity set to Normal
  • Type set to Bug

comment:5 Changed 5 years ago by aaugustin

  • UI/UX unset

Change UI/UX from NULL to False.

comment:6 Changed 5 years ago by aaugustin

  • Easy pickings unset

Change Easy pickings from NULL to False.

comment:7 Changed 15 months ago by giuliettamasina

  • Cc markus.magnuson@… added

It is still possible to trigger this error, but it seems like aggregate() and annotate() would since long be the preferred way to carry out anything similar to this example.

Last edited 15 months ago by giuliettamasina (previous) (diff)

comment:8 Changed 13 months ago by timgraham

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

I agree that the aggregate() and annotate() methods should be used these days, so I don't see much value in fixing this issue.

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