Changes between Version 1 and Version 2 of Ticket #31549


Ignore:
Timestamp:
May 8, 2020, 5:04:42 AM (5 years ago)
Author:
Mariusz Felisiak
Comment:

queryset.query is a helper, it doesn't produce SQL that can be executed directly in a database console, see #25705.

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #31549

    • Property Resolutioninvalid
    • Property Status newclosed
    • Property Summary Diffrent result from connectionWrong results when executing QuerySet.query.
  • Ticket #31549 – Description

    v1 v2  
    11We have a class:
    2 
     2{{{
    33from django.db.models import models
    44class MyModel(models.Model):
    55    import_at = models.DateField( db_index=True, null=True, default=None,)
    6 
     6}}}
    77then I can get some results by:
    8 
     8{{{
    99queryset = MyModel.objects.filter(import_at__month=5, import_at__year=import_at[0])
    1010print(queryset.count())
     11}}}
    1112It will print  4
    1213
    1314but when I used connection, I got diffrent result:
    14 
     15{{{
    1516from django.db import transaction, connection
    1617with connection.cursor() as cursor:
    1718    cursor.execute(queryset.query)
    1819    print(len(cursor.fetchall()))
    19 
     20}}}
    2021It will print 0
    2122
Back to Top