Opened 5 years ago
Last modified 5 years ago
#31549 closed Bug
Diffrent result from connection — at Version 1
Reported by: | Lawes | Owned by: | nobody |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | 2.0 |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description (last modified by )
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_atmonth=5, import_atyear=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.