Skip to content

Compare integer fields with integers beyond their range as a bigint - #2360

Draft
Flo0807 wants to merge 1 commit into
feature/adapter-neutral-filters-and-metricsfrom
fix/cast-condition-values
Draft

Flo0807 wants to merge 1 commit into
feature/adapter-neutral-filters-and-metricsfrom
fix/cast-condition-values

Conversation

@Flo0807

@Flo0807 Flo0807 commented Oct 16, 2026 •

Copy link
Copy Markdown
Collaborator

Based on #2340.

A range filter on an integer column crashed the index view for a number beyond the range of the column, e.g. ?filters[likes][start]=3000000000 in the demo: Postgrex can't encode 3000000000 for an integer column, or 10^20 for any integer column (DBConnection.EncodeError). Users can reach this by typing a number in the filter or by editing the URL. develop has the same crash; #2366 notes it as not covered.

The Ecto adapter now turns the comparison of an integer field with such an integer into a comparison it can run, with the same items:

  • An integer beyond the range of an integer is passed as a bigint ($1::bigint), which Postgres compares with any integer column.
  • An integer beyond the range of a bigint becomes the bound of a bigint, e.g. likes >= 10^20 becomes likes > 9223372036854775807.

As before, these comparisons don't keep items whose field is nil, also when negated. The fix lives in the adapter, so it applies to every condition of a filter and to the :where of a metric, not only to the Range filter. Integers within the range of an integer, other fields and other values (fractions, strings) are cast to the type of the field as before. Fractions on integer fields are handled by #2366, which rejects them in the Range filter.

Testing

  • Merged with Let the adapter turn filter conditions and metric aggregates into queries #2340's expressions (2026-10-28): the bigint comparison moved into the translation of expressions (Backpex.Adapters.Ecto.Where), so it also applies to fields of related items, e.g. expr(user.age < 3_000_000_000). The unit tests use expressions and cover a path and a flipped comparison. mix test incl. integration_test/ 1431 passed (180 doctests), mix test --only e2e 60 passed, mix credo, mix format --check-formatted and the 47 demo tests pass.
  • Merged with the updated Let the adapter turn filter conditions and metric aggregates into queries #2340 (2026-10-28): Move the feature tests into the library and measure coverage #2435 moved the demo filter tests into the library, so the new test is in integration_test/index/filters_test.exs. It fails with DBConnection.EncodeError without this fix. mix test incl. integration_test/ 1394 passed (171 doctests), mix test --only e2e 60 passed, bun run lint:standard, bun run test:js, mix credo and the 47 demo tests pass.
  • Library: MIX_ENV=test mix lint (164 doctests, 655 tests) and mix docs --warnings-as-errors pass. New tests cover the bigint parameter, the bigint bounds for every operator, negation and the values left to the cast.
  • Demo: filter_live_test.exs passes (25 tests). The new test filters the likes beyond the range of an integer and a bigint; with the adapter of Let the adapter turn filter conditions and metric aggregates into queries #2340 it fails with DBConnection.EncodeError.

@Flo0807 Flo0807 added the bug Something isn't working label Oct 16, 2026
@Flo0807
Flo0807 added this pull request to stack #2339 October 16, 2026 08:30
@Flo0807 Flo0807 self-assigned this Oct 16, 2026
@Flo0807 Flo0807 changed the title Compare integer fields with fractions and large numbers as with integers Compare integer fields with integers beyond their range as a bigint Oct 20, 2026
@Flo0807
Flo0807 removed this pull request from stack #2339 October 28, 2026 15:41
@codecov

codecov Bot commented Nov 12, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 80.00000% with 3 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
lib/backpex/adapters/ecto/where.ex 80.00% 3 Missing ⚠️

📢 Thoughts on this report? Let us know!

- Compare integer fields with fractions and large numbers as with integers
- Compare integer fields only with integers beyond their range as a bigint
@Flo0807
Flo0807 force-pushed the feature/adapter-neutral-filters-and-metrics branch from f58d61e to 7d25e7d Compare November 13, 2026 09:46
@Flo0807
Flo0807 force-pushed the fix/cast-condition-values branch from c5ec241 to 3ed3707 Compare November 13, 2026 09:46

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant