Skip to content

feat: add paginate_by_default? option to read actions#2648

Merged
zachdaniel merged 1 commit intoash-project:mainfrom
juanm07:feat/paginate-by-default
Mar 25, 2026
Merged

feat: add paginate_by_default? option to read actions#2648
zachdaniel merged 1 commit intoash-project:mainfrom
juanm07:feat/paginate-by-default

Conversation

@juanm07
Copy link
Copy Markdown
Contributor

@juanm07 juanm07 commented Mar 25, 2026

Contributor checklist

Leave anything that you believe does not apply unchecked.

  • I accept the AI Policy, or AI was not used in the creation of this PR.
  • Bug fixes include regression tests
  • Chores
  • Documentation changes
  • Features include unit/acceptance tests
  • Refactoring
  • Update dependencies

(this is my first pr ever :) )

Copilot AI review requested due to automatic review settings March 25, 2026 03:26
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_limit when paginate_by_default? is enabled and page is nil.
  • 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
Copy link

Copilot AI Mar 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
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

Copilot uses AI. Check for mistakes.
Comment on lines +153 to 158
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
]
Copy link

Copilot AI Mar 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
| [`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. |
Copy link

Copilot AI Mar 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
| [`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`. |

Copilot uses AI. Check for mistakes.
@zachdaniel zachdaniel merged commit 48de293 into ash-project:main Mar 25, 2026
48 of 49 checks passed
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.

Support paginate_by_default? when required?: false in pagination

3 participants