#36693: The "default" argument for ArrayAgg is being ignored
-------------------------------------+-------------------------------------
     Reporter:  Bryant Glisson       |                    Owner:  (none)
         Type:  Bug                  |                   Status:  closed
    Component:  Database layer       |                  Version:  5.2
  (models, ORM)                      |
     Severity:  Normal               |               Resolution:  invalid
     Keywords:  annotation, array    |             Triage Stage:
  aggregation                        |  Unreviewed
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
Changes (by ontowhee):

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

Comment:

 Hello! Is there a record for your model that has a None value for the
 `sites` field? If there are no records for your model, the expected return
 value should be an empty list, given the default that you have provided.
 However, if there is at least one record, the aggregation is expected to
 return a list with some items in it.

 There are examples of how the default parameter is used in
 
[https://github.com/django/django/blob/43933a1dca07047e95ec990d9289d0212668009e/tests/postgres_tests/test_aggregates.py#L116
 test_default_argument]. In this test, all the records for
 `AggregateTestModel` have been deleted, and the aggregations are returning
 the values specified in the default parameter.

 In the attempt to reproduce your case, I created one record of the
 AggregateTestModel with an integer_field of `None`, and observed that the
 aggregation returned a list with one `None` value. Is this similar to what
 you are observing in your application?

 {{{
         AggregateTestModel.objects.create(char_field="hello")
         aggregation = ArrayAgg("integer_field", default=[])
         expected_result = []
         with self.assertNumQueries(1):
             values = AggregateTestModel.objects.aggregate(
                 aggregation=aggregation
             )
             self.assertEqual(values, {"aggregation": expected_result})
 }}}

 Closing this ticket because the default parameter is working as expected.
 If this assessment is incorrect, feel free to reopen and provide more
 details on reproducing the bug.

 If you have further questions on how to use Django, feel free to ask for
 help from a friendly community member on ​[https://chat.djangoproject.com/
 Discord] or the [https://forum.djangoproject.com/ Django forum]!
-- 
Ticket URL: <https://code.djangoproject.com/ticket/36693#comment:1>
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 visit 
https://groups.google.com/d/msgid/django-updates/0107019a2cf12c23-3d65fc1b-1835-4f03-966f-e4c61ae8904a-000000%40eu-central-1.amazonses.com.

Reply via email to