Opened 6 years ago
Last modified 6 years ago
#30480 closed Bug
Discrepancy in `DateTime` field value If the django orm union() is used with the EmptyQuerySet. — at Initial Version
| Reported by: | Shashank Parekh | Owned by: | nobody | 
|---|---|---|---|
| Component: | Database layer (models, ORM) | Version: | dev | 
| 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
class detail(models.Model):
      date_field = models.DateTimeField(null=True, index=True)
      guid = models.CharField(null=True, index=True)
      mobile = models.CharField(null=True, index=True)
      id = models.CharField(null=True, index=True)
p=detail.objects.filter(guid__in=[]).order_by('-date_field')
q=detail.objects.filter(mobile__in=['8970405058']).order_by('-date_field')
v = (p.union(q)).order_by('-date_field')
v[0].date_field   # Output is  '2018-10-08 12:51:39'.
 For this case, instead of getting datetime value, getting the string value.
p=detail.objects.filter(guid__in=['some_garbage_value']).order_by('-date_field')
q=detail.objects.filter(mobile__in=['8970405058']).order_by('-date_field')
v = (p.union(q)).order_by('-date_field')
v[0].date_field .  # Output is datetime.datetime(2018, 10, 8, 12, 51, 39)
If  I don't pass the empty array in filtering then getting the DateTime value.
p=detail.objects.filter(guid__in=['some_garbage_value']).order_by('-date_field')
q=detail.objects.filter(mobile__in=['8970405058']).order_by('-date_field')
v = (p.union(q))
v[0].date_field .  # Output is datetime.datetime(2018, 10, 8, 12, 51, 39)
If  I pass the empty array but withour order_by clause then getting the DateTime value.
There is a discrepancy in DateTime field value If the union is used with the EmptyQuerySet.
  Note:
 See   TracTickets
 for help on using tickets.