Skip to content

Fix empty composite tuple predicates - #65

Closed
mathiusj wants to merge 1 commit into
Shopify:mainfrom
mathiusj:ae-task-5073-predicatebuilder-composite-tuple-where-w
Closed

mathiusj wants to merge 1 commit into
Shopify:mainfrom
mathiusj:ae-task-5073-predicatebuilder-composite-tuple-where-w

Conversation

@mathiusj

@mathiusj mathiusj commented Sep 16, 2026 •

Copy link
Copy Markdown

Summary

Composite tuple where conditions with empty value lists generated an empty SQL grouping. PostgreSQL and MySQL reject the resulting WHERE () clause.

This change emits 1=0 through an empty In predicate. The relation matches no rows and does not send a database query.

Approach

  • Handle empty query groups in grouping_queries, beside the existing one-query and many-query cases.
  • Build the empty In predicate with the first relevant attribute, so Active Record identifies the relation as a contradiction.
  • Apply the same behavior to empty value lists for composite tuples and composite associations.
  • Preserve other hash conditions and the existing non-empty tuple behavior.
  • Add regression tests that require valid SQL, no matching rows, and no database query.

Upstream status

The rails/rails main branch at 216b59017fd1 has no equivalent fix. This patch is small and suitable for an upstream submission.

Test plan

  • cd activerecord && bin/test test/cases/relation/where_test.rb test/cases/relation/predicate_builder_test.rb
  • bundle exec rubocop activerecord/lib/active_record/relation/predicate_builder.rb activerecord/test/cases/relation/where_test.rb
  • git diff --check

Co-authored-by: GPT-5.6-sol noreply@openai.com
Orchestrated-by: ae noreply@shopify.com

@mathiusj
mathiusj force-pushed the ae-task-5073-predicatebuilder-composite-tuple-where-w branch from 593e9b9 to 671b45d Compare September 16, 2026 17:13
Empty tuple value lists built an empty grouping, which generated
invalid SQL. Return a no-match predicate while preserving other hash
conditions.

Co-authored-by: GPT-5.6-sol <noreply@openai.com>
Orchestrated-by: ae <noreply@shopify.com>
@mathiusj
mathiusj force-pushed the ae-task-5073-predicatebuilder-composite-tuple-where-w branch from 671b45d to b26106f Compare September 17, 2026 17:57
@mathiusj mathiusj closed this Sep 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant