Opened 15 years ago

Last modified 9 years ago

#11329 closed

get_count generates incorrect SQL for query sets with extra 'select' and 'where' — at Initial Version

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

Extending an example on extra 'select' from http://docs.djangoproject.com/en/1.0/ref/models/querysets/ with an extra 'with' and calling get_count:

Blog.objects.extra(

select={

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

},
where=entry_count=0

).query.get_count()

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.

Change History (0)

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