﻿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
32044	Add remove_nulls option to Postgres ArrayAgg method	Matthieu Rigal	nobody	"A common issue when using ArrayAgg is that when the list of values of a related field is empty, it returns `[None]` instead of `[]`. It is very disturbing the first time one encounters that and led to many stackoverflows questions for example. The issue comes from Postgres itself, however Django could provide an option solve it easily. This is what I want to propose here.

I think we could add a key-word argument, false by default, maybe called `remove_nulls`, or `without_null(s)` that would add one of the following:

1. Auto-filter for null values

As notified in this answer https://stackoverflow.com/a/55107410/1504046 it is possible to filter null values out to prevent the problem. Probably the most efficient solution and I am not aware of downsides to this. Actually, I don't think there is a downside to have it always filtered out (except breaking changes with previous versions)

2. Use array_remove(, NULL) on the Postgres side

On the Postgres-side, there is a dedicated  array_function called array_remove() (existing since 9.3 https://www.postgresql.org/docs/9.3/functions-array.html) which is ""less invasive"" as it only modifies the result of the output of the select itself, not the query logic behind. It is well described in this answer https://stackoverflow.com/a/33145722/1504046

Cheers,
Matthieu"	New feature	closed	contrib.postgres	3.1	Normal	wontfix	postgres, aggregate		Unreviewed	0	0	0	0	0	0
