#18870: QuerySet.count() generates invalid sql when used with select_related() and extra() -------------------------------+---------------------- Reporter: bkvaiude@… | Owner: B001 Type: Uncategorized | Status: new Component: Uncategorized | Version: 1.3-beta Severity: Normal | Keywords: Triage Stage: Unreviewed | Has patch: 0 Easy pickings: 0 | UI/UX: 0 -------------------------------+---------------------- total = IntentStats.objects.filter().extra(where=['date(`intentapp_intent`.`created_at`) between \''+start_date.__str__()+'\' and \''+end_date.__str__()+'\''],tables=['intentapp_intent']).select_related('intent')
total_query=total.query -------------------------------------------------------------------------------------------------------------- SELECT `intentapp_intentstats`.`id`, `intentapp_intentstats`.`intent_id`, `intentapp_intentstats`.`category`, `intentapp_intentstats`.`support_count`, `intentapp_intentstats`.`comment_count`, `intentapp_intentstats`.`adoption_count`, `intentapp_intentstats`.`updated_at`, `intentapp_intent`.`id`, `intentapp_intent`.`user_id`, `intentapp_intent`.`body`, `intentapp_intent`.`category`, `intentapp_intent`.`why_important`, `intentapp_intent`.`can_help`, `intentapp_intent`.`inspiration`, `intentapp_intent`.`parent_id`, `intentapp_intent`.`deleted`, `intentapp_intent`.`sponsored`, `intentapp_intent`.`fulfilled_at`, `intentapp_intent`.`created_at`, `intentapp_intent`.`updated_at`, `intentapp_intent`.`legacy_intent_id`, `intentapp_intent`.`homepage_location` FROM `intentapp_intentstats` INNER JOIN `intentapp_intent` ON (`intentapp_intentstats`.`intent_id` = `intentapp_intent`.`id`) WHERE date(`intentapp_intent`.`created_at`) between '2012-08-27' and '2012-08-28' -------------------------------------------------------------------------------------------------------------- total=total.count() I got this output through django shell Ans: 0 But when call it in my app it gives me XXX count. SQL -------------------------------------------------------------------------------------------------------------- SELECT COUNT(*) FROM `intentapp_intentstats` , `intentapp_intent` WHERE date(`intentapp_intent`.`created_at`) between '2012-08-27' and '2012-08-28' -------------------------------------------------------------------------------------------------------------- Please let me any solution for above issue. thanks in advanced. -- Ticket URL: <https://code.djangoproject.com/ticket/18870> Django <https://code.djangoproject.com/> The Web framework for perfectionists with deadlines. -- You received this message because you are subscribed to the Google Groups "Django updates" group. To post to this group, send email to django-updates@googlegroups.com. To unsubscribe from this group, send email to django-updates+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.