Repository navigation
Conversation
This was referenced Oct 28, 2026
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
- Describe the resource in the adapter and cast expressions with it - Refer to before_changeset/6 of v0.24 without a link
Flo0807
force-pushed
the
feature/describe-resource
branch
from
November 13, 2026 09:46
0b54c27 to
d7e1096
Compare
This branch has not been deployed
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.
Stack (merge in this order)
developSecond step of the adapter-neutral data access after the expressions of #2340: the adapter describes the resource, and Backpex checks and casts expressions with that description, so an adapter gets values of the right type and a typo in a filter fails with a clear message.
describe/2replacesassociation/2andfield_type/2c:Backpex.Adapter.describe/2. It returns aBackpex.Adapter.Descriptionof the items of the resource, or, with a path of relationships such as[:author], of the related items at its end, ornilfor an unknown path::primary_key- the names of the fields of the primary key.:fields- a map of field names to their:type(an Ecto type such as:integerorEcto.Enum, which an adapter for another data source maps its types to) and:primitivetype.:relationships- the mapsassociation/2returned::field,:cardinality,:owner_keyand:through.Backpex.Resource.describe/2calls it.Backpex.Resource.association/2andBackpex.Resource.field_type/2stay as helpers that read the description, so BelongsTo, HasManyThrough,default_attrs/3and the Range filter are unchanged.__schema__/1,2, also at the end of through associations.Expressions are checked and cast
Backpex.Expr.cast/2checks the fields of an expression against the description: unknown fields, unknown relationships and paths through relationships to many items raise anArgumentErrorthat names the field. It casts the values of comparisons and ofinto the types of their fields, e.g.expr(likes >= "10")becomesexpr(likes >= 10)andexpr(role == "admin")becomesexpr(role == :admin)for anEcto.Enum, also on paths and insideexists/2. A value that can't be cast is kept, so the adapter decides about it. Parts of strings (contains/2and friends) and native expressions are kept.Ecto.Changesetfor casting, as the adapter boundary test requires.:whereof metrics withBackpex.Resource.cast_expr/2.Backpex.Adapters.Ecto.apply_filters/5takes the LiveResource for that;apply_filters/4keeps working without casting.Breaking changes (v0.25 upgrade guide)
describe/2instead ofassociation/2and the optionalfield_type/2, and should pass expressions toBackpex.Resource.cast_expr/2.Not in this PR
read/1) and thesupports?/2capabilities with an in-memory fallback, the next steps of the expression design.Testing
mix testincl.integration_test/1449 passed (182 doctests),mix test --only e2e60 passed,mix compile --warnings-as-errors --force,mix format --check-formatted,mix credo,mix docswithout warnings,mix deps.unlock --check-unusedandmix gettext.extract --check-up-to-datepass.Backpex.Expr.cast/2with a fake description (casting, parameterized types, paths,exists, kept values, errors),describe/2tests of the Ecto adapter (fields, associations, through associations, paths), and integration tests that cast with a LiveResource against PostgreSQL.bun run lintpass.