from django.db.models import models
class MyModel(models.Model):
import_at = models.DateField( db_index=True, null=True, default=None,)
then I can get some results by:
queryset = MyModel.objects.filter(import_at__month=5,
import_at__year=import_at[0])
print(queryset.count())
>>> 4
but when I used connection, I got diffrent result:
from django.db import transaction, connection
with connection.cursor() as cursor:
cursor.execute(queryset.query)
print(len(cursor.fetchall()))
>>> 0
I got 0 !
If I using __month or __year, and get result by
cursor.execute(queryset.query), we have diffrent result from connection.
--
Ticket URL: <https://code.djangoproject.com/ticket/31549>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
Old description:
> We have a class:
>
> from django.db.models import models
> class MyModel(models.Model):
> import_at = models.DateField( db_index=True, null=True,
> default=None,)
>
> then I can get some results by:
>
> queryset = MyModel.objects.filter(import_at__month=5,
> import_at__year=import_at[0])
> print(queryset.count())
> >>> 4
>
> but when I used connection, I got diffrent result:
>
> from django.db import transaction, connection
> with connection.cursor() as cursor:
> cursor.execute(queryset.query)
> print(len(cursor.fetchall()))
>
> >>> 0
>
> I got 0 !
>
> If I using __month or __year, and get result by
> cursor.execute(queryset.query), we have diffrent result from connection.
New description:
We have a class:
from django.db.models import models
class MyModel(models.Model):
import_at = models.DateField( db_index=True, null=True, default=None,)
then I can get some results by:
queryset = MyModel.objects.filter(import_at__month=5,
import_at__year=import_at[0])
print(queryset.count())
It will print 4
but when I used connection, I got diffrent result:
from django.db import transaction, connection
with connection.cursor() as cursor:
cursor.execute(queryset.query)
print(len(cursor.fetchall()))
It will print 0
I got 0 !
If I using __month or __year, and get result by
cursor.execute(queryset.query), we have diffrent result from connection.
--
--
Ticket URL: <https://code.djangoproject.com/ticket/31549#comment:1>
* status: new => closed
* resolution: => invalid
Old description:
> We have a class:
>
> from django.db.models import models
> class MyModel(models.Model):
> import_at = models.DateField( db_index=True, null=True,
> default=None,)
>
> then I can get some results by:
>
> queryset = MyModel.objects.filter(import_at__month=5,
> import_at__year=import_at[0])
> print(queryset.count())
> It will print 4
>
> but when I used connection, I got diffrent result:
>
> from django.db import transaction, connection
> with connection.cursor() as cursor:
> cursor.execute(queryset.query)
> print(len(cursor.fetchall()))
>
> It will print 0
>
> I got 0 !
>
> If I using __month or __year, and get result by
> cursor.execute(queryset.query), we have diffrent result from connection.
New description:
We have a class:
{{{
from django.db.models import models
class MyModel(models.Model):
import_at = models.DateField( db_index=True, null=True, default=None,)
}}}
then I can get some results by:
{{{
queryset = MyModel.objects.filter(import_at__month=5,
import_at__year=import_at[0])
print(queryset.count())
}}}
It will print 4
but when I used connection, I got diffrent result:
{{{
from django.db import transaction, connection
with connection.cursor() as cursor:
cursor.execute(queryset.query)
print(len(cursor.fetchall()))
}}}
It will print 0
I got 0 !
If I using __month or __year, and get result by
cursor.execute(queryset.query), we have diffrent result from connection.
--
Comment:
`queryset.query` is a helper, it doesn't produce SQL that can be executed
directly in a database console, see #25705.
--
Ticket URL: <https://code.djangoproject.com/ticket/31549#comment:2>