Changes between Version 1 and Version 2 of Ticket #31549
- Timestamp:
- May 8, 2020, 5:04:42 AM (5 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
Ticket #31549
- Property Resolution → invalid
- Property Status new → closed
- Property Summary Diffrent result from connection → Wrong results when executing QuerySet.query.
-
Ticket #31549 – Description
v1 v2 1 1 We have a class: 2 2 {{{ 3 3 from django.db.models import models 4 4 class MyModel(models.Model): 5 5 import_at = models.DateField( db_index=True, null=True, default=None,) 6 6 }}} 7 7 then I can get some results by: 8 8 {{{ 9 9 queryset = MyModel.objects.filter(import_at__month=5, import_at__year=import_at[0]) 10 10 print(queryset.count()) 11 }}} 11 12 It will print 4 12 13 13 14 but when I used connection, I got diffrent result: 14 15 {{{ 15 16 from django.db import transaction, connection 16 17 with connection.cursor() as cursor: 17 18 cursor.execute(queryset.query) 18 19 print(len(cursor.fetchall())) 19 20 }}} 20 21 It will print 0 21 22