Skip to content

Fix build_join_buckets ArgumentError for non-OuterJoin Arel nodes#24

Merged
malomalo merged 1 commit intomasterfrom
fix-build-join-buckets-arel-node-handling
Feb 16, 2026
Merged

Fix build_join_buckets ArgumentError for non-OuterJoin Arel nodes#24
malomalo merged 1 commit intomasterfrom
fix-build-join-buckets-arel-node-handling

Conversation

@waratuman
Copy link
Collaborator

@waratuman waratuman commented Feb 16, 2026

Problem

Two related issues when filter_on uses non-standard join types:

1. build_join_buckets only handles OuterJoin in the left outer joins block

The override raises ArgumentError: "only Hash, Symbol and Array are allowed" when left_outer_joins_values contains an Arel::Nodes::Join subclass other than OuterJoin (e.g. InnerJoin). These nodes flow through select_named_joinsselect_association_list, which yields anything that is not a Hash/Symbol/Array/JoinDependency to the block. The block only handled CTEJoin and OuterJoin.

2. Proc joins from filter_on not resolved in build_filter_joins (fixes #25)

When filter_on is called with a lambda as dependent_joins:

filter_on :columns, -> (filters) {
  if filters.is_a?(Array) && filters.size > 1
    # return Arel join sources
  else
    :columns
  end
} do |klass, table, key, value, rt, at|
  # filter logic
end

The Proc was pushed raw into relations in build_filter_joins, then sent to left_outer_joins! in filter!, where select_association_list cannot handle it.

Fix

query_methods_extension.rb: Broadened the elsif from Arel::Nodes::OuterJoin to Arel::Nodes::Join, matching the pattern already used in the joins_values block below.

predicate_builder_extension.rb: Added Proc handling in build_filter_joins — when js is a Proc, call it with the filter value to resolve the actual joins before classifying them as relations or custom.

Other changes

  • Added tests for filter_on with Arel join nodes and Proc joins
  • Updated CI matrix: dropped Rails 7.1 (EOL), bumped 8.1.1 → 8.1.2

The left outer joins block in build_join_buckets only handled
Arel::Nodes::OuterJoin, raising ArgumentError for other Join
subclasses like InnerJoin. This occurs when filter_on callbacks
produce Arel join sources that end up in left_outer_joins_values
and pass through select_association_list.

Broaden the check to Arel::Nodes::Join, matching the pattern
already used in the joins_values block below.

Also resolve Proc joins in build_filter_joins (#25). When
filter_on specifies a lambda as dependent_joins, the Proc was
pushed raw into relations instead of being called first. Now
the Proc is called with the filter value to resolve the actual
joins before classifying them.

Also update CI matrix to drop Rails 7.1 (EOL) and bump 8.1.1
to 8.1.2.
@waratuman waratuman force-pushed the fix-build-join-buckets-arel-node-handling branch from 2f189f7 to 7f09e83 Compare February 16, 2026 05:55
@malomalo malomalo merged commit 9951b79 into master Feb 16, 2026
17 of 18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Proc joins from filter_on not resolved in build_filter_joins

2 participants

Comments