Repository navigation
Conversation
include_nil? defaults to false, and the lateral strategy honours it for sorted list aggregates with FILTER (WHERE field IS NOT NULL), or by folding the nil check into the aggregate's own filter. A list with no sort, on the aggregate or on the relationship, was built as a plain array_agg(field) and kept the nils. Apply the same nil handling to the unsorted branch, with and without uniq?.
This was referenced Sep 26, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The problem
On AshPostgres, a
listaggregate without a sort includesnilvalues, althoughinclude_nil?defaults tofalse:A sorted list, or one over a relationship with a
sort, correctly leaves the nil out. This predates the aggregate strategies refactor.Why
In the lateral strategy, the sorted branch of the list aggregate handles
include_nil?. It either addsFILTER (WHERE field IS NOT NULL), or folds the nil check into the aggregate's own filter. The unsorted branch builds a plainarray_agg(field)(orarray_agg(DISTINCT field)), with no nil handling.The fix
The unsorted branch now handles nils the same way as the sorted one:
include_nil?: truekeeps the plainarray_agg.filter_field/6, which addsnot is_nil(field)to that filter.FILTER (WHERE field IS NOT NULL), with or withoutDISTINCT.Tests
The regression test is in AshPostgres, where the bug shows up: wtsnz/ash_postgres#6. It covers an unsorted list,
uniq?, a list with its own filter, andinclude_nil?: true.[nil, "aaa", "aaa", "bbb"].ASH_SQL_VERSION=local).Also checked:
mainin the local test database, and nothing new.Found by
The data-layer conformance suite (wtsnz/ash#7), gap
unsorted-list-nil. With this branch, both Postgres scenarios behind it (values.list_unsorted,root.list_unsorted) pass, and no other result changes.