[Django] #27990: QuerySet.count() raises ValueError when QuerySet.union() is used

20 views
Skip to first unread message

Django

unread,
Mar 28, 2017, 1:13:04 PM3/28/17
to django-...@googlegroups.com
#27990: QuerySet.count() raises ValueError when QuerySet.union() is used
-------------------------------------+-------------------------------------
Reporter: kapil | Owner: nobody
garg |
Type: Bug | Status: new
Component: Database | Version: 1.10
layer (models, ORM) |
Severity: Normal | Keywords:
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
When we get objects from a model and do union then the resulted
QuerySet.count() raises ValueError due to the presence of Non-Numeric
first Field.

Eg.


{{{
class SomeModel(models.Model):
name = models.CharField(max_length=10, default='example')

>>> from bug.models import SomeModel
>>> e1 = SomeModel(name='current')
>>> e1.save()
>>> e2 = SomeModel()
>>> e2.save()
>>> qs1 = SomeModel.objects.filter(name__startswith='ex').only('name')
>>> qs2 = SomeModel.objects.filter(name__startswith='cu').only('name')
>>> qs = qs1.union(qs2)
>>> print(qs.count())
>>> #raises ValueError : invalid literal for int() with base 10
}}}

If the first field contained in queryset is numeric then this error is not
raised.

Eg. remove .only() method above on both querysets and then .count() with
return correct result.

--
Ticket URL: <https://code.djangoproject.com/ticket/27990>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Mar 28, 2017, 1:21:32 PM3/28/17
to django-...@googlegroups.com
#27990: QuerySet.count() raises ValueError when QuerySet.union() is used
-------------------------------------+-------------------------------------
Reporter: kapil garg | Owner: nobody
Type: Bug | Status: closed
Component: Database layer | Version: 1.10
(models, ORM) |
Severity: Normal | Resolution: invalid
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by kapil garg):

* status: new => closed
* resolution: => invalid


Comment:

I found the reason. union() does not support count().

--
Ticket URL: <https://code.djangoproject.com/ticket/27990#comment:1>

Django

unread,
Mar 29, 2017, 10:01:53 AM3/29/17
to django-...@googlegroups.com
#27990: QuerySet.count() raises ValueError when QuerySet.union() is used
-------------------------------------+-------------------------------------
Reporter: kapil garg | Owner: nobody
Type: Bug | Status: closed
Component: Database layer | Version: 1.10
(models, ORM) |
Severity: Normal | Resolution: invalid
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Tim Graham):

I opened #27995 to raise a descriptive error on unsupported operations
following `QuerySet.union()`.

--
Ticket URL: <https://code.djangoproject.com/ticket/27990#comment:2>

Reply all
Reply to author
Forward
0 new messages