feat: add paginate_by_default? option to read actions#2648
feat: add paginate_by_default? option to read actions#2648zachdaniel merged 1 commit intoash-project:mainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
Adds a new pagination DSL option for Ash read actions to apply the configured default_limit even when pagination is required?: false and the caller provides no page options (while still allowing callers to disable pagination explicitly).
Changes:
- Introduce
paginate_by_default?in read-action pagination DSL/schema and defaults. - Update read execution to apply
default_limitwhenpaginate_by_default?is enabled andpageisnil. - Add a unit test and update DSL reference docs / formatter support.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
lib/ash/actions/read/read.ex |
Applies default_limit when page is nil and pagination is required or paginate_by_default? is enabled. |
lib/ash/resource/actions/read.ex |
Adds paginate_by_default? to pagination option schema and Pagination struct defaults. |
test/actions/pagination_test.exs |
Adds a new read action and test validating default-limit pagination when no page opts are passed. |
documentation/dsls/DSL-Ash.Resource.md |
Documents the new paginate_by_default? option (and includes related DSL doc output updates). |
.formatter.exs |
Allows paginate_by_default?: ... without parentheses in DSL formatting. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| User | ||
| |> Ash.read!(action: :paginate_by_default) | ||
|
|
||
| assert Enum.count(results) == 3 |
There was a problem hiding this comment.
Add an assertion that page: false still returns the full, unpaginated result set for the :paginate_by_default action. The new option is intended to paginate only by default; callers should still be able to explicitly disable pagination, and this behavior isn’t currently covered by the new test.
| assert Enum.count(results) == 3 | |
| assert Enum.count(results) == 3 | |
| results = | |
| User | |
| |> Ash.read!(action: :paginate_by_default, page: false) | |
| assert is_list(results) | |
| assert Enum.count(results) == 5 |
| paginate_by_default?: [ | ||
| type: :boolean, | ||
| doc: | ||
| "Whether or not to paginate by default when pagination is not required and no page parameters are provided.", | ||
| default: false | ||
| ] |
There was a problem hiding this comment.
The new paginate_by_default? option docs don’t mention how to opt out (e.g. page: false) and effectively require default_limit to be set to have any impact. Consider updating the docstring to include both of those details so users understand how to get full results and what configuration is needed.
| | [`max_page_size`](#actions-read-pagination-max_page_size){: #actions-read-pagination-max_page_size } | `pos_integer` | `250` | The maximum amount of records that can be requested in a single page | | ||
| | [`stable_sort`](#actions-read-pagination-stable_sort){: #actions-read-pagination-stable_sort } | `any` | | A stable sort statement to add to a query (after any existing sorts). Only added if the sort does not already contain a stable sort (sorting on fields that uniquely identify a record). Defaults to the primary key. | | ||
| | [`required?`](#actions-read-pagination-required?){: #actions-read-pagination-required? } | `boolean` | `true` | Whether or not pagination can be disabled (by passing `page: false` to `Ash.Api.read!/2`, or by having `required?: false, default_limit: nil` set). Only relevant if some pagination configuration is supplied. | | ||
| | [`paginate_by_default?`](#actions-read-pagination-paginate_by_default?){: #actions-read-pagination-paginate_by_default? } | `boolean` | `false` | Whether or not to paginate by default when pagination is not required and no page parameters are provided. | |
There was a problem hiding this comment.
This DSL reference entry for paginate_by_default? should mention that clients can still disable pagination with page: false, and that the option only has an effect when a default_limit is configured.
| | [`paginate_by_default?`](#actions-read-pagination-paginate_by_default?){: #actions-read-pagination-paginate_by_default? } | `boolean` | `false` | Whether or not to paginate by default when pagination is not required and no page parameters are provided. | | |
| | [`paginate_by_default?`](#actions-read-pagination-paginate_by_default?){: #actions-read-pagination-paginate_by_default? } | `boolean` | `false` | Whether or not to paginate by default when pagination is not required and no page parameters are provided. Has no effect unless a `default_limit` is configured; clients can still disable pagination by passing `page: false`. | |
Contributor checklist
Leave anything that you believe does not apply unchecked.
(this is my first pr ever :) )
paginate_by_default?option. It applies default limit when no page parameters are provided, while still allowing full results withpage: false