Skip to content

fix: ignore and/or filters whose entries are all empty - #655

Closed
breken-ai wants to merge 1 commit into
supabase:masterfrom
breken-ai:fix/empty-compound-filter-entries
Closed

breken-ai wants to merge 1 commit into
supabase:masterfrom
breken-ai:fix/empty-compound-filter-entries

Conversation

@breken-ai

Copy link
Copy Markdown

What kind of change does this PR introduce?

Bug fix.

What is the current behavior?

An and/or filter whose entries are all empty fails with a raw SQL error, where it should be ignored:

{ accountCollection(filter: {or: [{}]}) { edges { node { id } } } }
# {"errors": [{"message": "syntax error at or near \")\""}]}

The same happens with and: [{}], with not: {or: [{}]}, on update/delete mutation filters, and, most commonly in practice, when an entry's only operator comes from an omitted variable:

query ($email: String) { accountCollection(filter: {or: [{email: {eq: $email}}]}) { ... } }
# variables: {}  ->  syntax error at or near ")"

create_filters drops each empty entry (the "Avoid argumentless and" branch). If nothing is left, it still pushes CompoundFilterBuilder::Or(vec![]), which transpiles to ().

What is the new behavior?

When no entries remain, the compound filter is skipped, just as or: [] / and: [] already are. The docs say "Empty filters are ignored, i.e. they behave as if the operator was not specified at all". Mixed lists are unchanged: or: [{}, {id: {eq: 2}}] still returns id 2 only.

Additional context

  • New regression test test/sql/compound_filters_empty_entries.sql covers or: [{}], and: [{}], the omitted-variable case, a mixed list, not around an empty or, and an update mutation.
  • Proof, run with the repo's dockerfiles/db/Dockerfile toolchain (PG 17, pgrx 0.19.2):
    • On master, every empty-entry case in the new test returns syntax error at or near ")".
    • With the fix, ./bin/installcheck passes all 123 tests.
    • cargo fmt --check and cargo clippy --features pg17 -- -D warnings are clean.

This PR was prepared with AI assistance (Claude). I reviewed and tested the change as described above.

🤖 Generated with Claude Code

`filter: {or: [{}]}` (or `and`, or an entry whose only operator comes
from an omitted variable) dropped each empty entry but still pushed the
compound filter, which transpiled to `()` and failed with a SQL syntax
error. Skip the compound filter when no entries remain, the same way an
empty list is already ignored.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@imor

imor commented Sep 27, 2026

Copy link
Copy Markdown
Contributor

Closing as this is 100% AI generated.

@imor imor closed this Sep 27, 2026
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.

2 participants