#34564: returning None instead of zero in Count annotation
-------------------------------------+-------------------------------------
     Reporter:  Amin Aminian         |                    Owner:  Amin
                                     |  Aminian
         Type:  Bug                  |                   Status:  assigned
    Component:  Database layer       |                  Version:  4.2
  (models, ORM)                      |
     Severity:  Normal               |               Resolution:
     Keywords:  count, orm,          |             Triage Stage:  Accepted
  annotate                           |
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------

Comment (by Amin Aminian):

 Thanks Simon for explaining `empty_result_set_value` usage.

 So, as far as I understood, if the query is going to return None, we
 return `empty_result_set_value` instead, without running the query. Right
 ? If it's right, there is still something that I'm missing.

 My point is, assume that we have a query that the compiler does not know
 that it is going to return None (normal queries like
 `objects.annotate(count=Count("..."))`). In this case, the query is going
 to be run, and the result would be fetched. Now why we can't use
 `empty_result_set_value` in case of result is None ?

 What I am saying is a code like this:

 {{{
 class BaseExpression:
     ...
     @cached_property
     def convert_value(self):
         field = self.output_field
         internal_type = field.get_internal_type()
         ...
         elif internal_type.endswith("IntegerField"):
             return (
                 lambda value, expression, connection:
 self.empty_result_set_value # instead of None
                 if value is None
                 else int(value)
             )
         ...
         return self._convert_value_noop
 }}}

 And about Python time conversions, we are already running this
 `convert_property` for each row.

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

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/010701881e9eb9aa-3820032b-b9ad-42bc-a4ea-899dd23f28b8-000000%40eu-central-1.amazonses.com.

Reply via email to