﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
35235	ArrayAgg() doesn't return default when filter contains __in=[].	Per Carlsen	Sharon Woo	"ArrayAgg changed the default return value in Django 5.0 to `None` instead of `[]`. The documentation recommends adding `default=Value([])` to make it return an empty list instead of `None`. My app requires empty lists to be returned, so I updated the code and noticed that the return type is inconsistent with the documentation when using the `filter` functionality of ArrayAgg.

Consider the following query. `filter_value` and `default` are variables, and given combinations seem to give inconsistent return values.

{{{
MyModel.objects.annotate(
    annotated_ids=ArrayAgg(
        ""my_other_model_set__id"",
        filter=Q(
            my_other_model_set__id__in=filter_value,
        ),
        default=default,
    )
).first().annotated_ids
}}}


`MyOtherModel` has a fk relation to `MyModel`, which we referenced via `my_other_model_set`. Consider the following input values for `filter_value` and `default`:

Example 1:
filter_value = [-1] # Or any other ID that does not exist
default = Value([])
This returns an empty list (`[]`), as expected because there are no results for ArrayAgg

Example 2:
filter_value = []
default = Value([])
BUG: This returns the string `'{}'` instead of an empty list. This also happens if we don't specify a `default` value. But if we give `default=[]` (without the `Value()`), the return value is consistent with the documentation.








"	Bug	closed	contrib.postgres	5.0	Normal	fixed	ArrayAgg	Simon Charette Nick Pope	Ready for checkin	1	0	0	0	0	0
