Invalid `page` options are an unrendered Spark.Options.ValidationError, and a non-list `page` raises
Versions: ash 3.33.3, Elixir 1.20.1 on OTP 29. Present on the default branch at a7a5105 (checked 2026-09-15).
Found by an AI assistant working with a human who was fuzz-testing their own application; reproduced in a minimal project with default settings.
Request
On a read action with pagination keyset?: true, offset?: true: Ash.read(Post, page: [after: "x", offset: 1]); also page: [limit: 0], [limit: -1], [limit: "x"], [limit: 1, offset: -1]. Through AshJsonApi: GET /posts?page[after]=x&page[offset]=1. And Ash.read(Post, page: "x").
Observed
{:error, %Ash.Error.Unknown{errors: [%Ash.Error.Unknown.UnknownError{error:
"** (Spark.Options.ValidationError) invalid value for :page option: unknown options [:offset], valid options are: [:before, :after, :limit, :filter, :count]"}]}}
(expected positive integer, got: 0 and so on for the others.) JSON:API answers 500. page: "x" raises FunctionClauseError in Access.get/3. By contrast page: [after: "x", limit: 1] returns Ash.Error.Invalid with Ash.Error.Page.InvalidKeyset.
Expected
An Ash.Error.Invalid describing the bad page options; a 400 on JSON:API.
Failure point
Ash.Page.page_opts/1, lib/ash/page/page.ex#L16-L33; the failure reaches Ash.Error.to_error_class/2 from lib/ash.ex#L3149-L3150.
Notes
AshGraphql hits the same unrendered error with first: 0 (reported there).
Reproduction
- Description, with the failure point at this release: https://github.com/grempe/ash-fuzz-repros#ashinvalid-page-options-unrendered
- Failing test: https://github.com/grempe/ash-fuzz-repros/blob/main/test/ash/invalid_page_options_test.exs
- Run:
mix setup && mix test test/ash/invalid_page_options_test.exsin https://github.com/grempe/ash-fuzz-repros
Hi, Im new to Ash. Will start working on this. Let me know if you have any advice or suggestions
@jbfawcett24 are you still planning to take this one? No rush, just checking so we do not both work on it.
If it helps, here is what I found when I traced it. Ash.Query.page/2 already turns a bad page into Ash.Error.Query.InvalidPage, so Post |> Ash.Query.page(limit: 0) |> Ash.read() is fine. The :page option of Ash.read/2 is declared in the read options schema as type: {:custom, Ash.Page, :page_opts, []}, so the same Ash.Page.page_opts/1 runs there too, but a failure surfaces as a Spark.Options.ValidationError from ReadOpts.validate/1, and the else branch of read/2 hands that to Ash.Error.to_error_class/2, which has no class for it. page: "x" raises because page_opts/1 does page_opts[:after] on whatever it gets. Ash.get/3, Ash.read_one/2 and Ash.read_first/2 validate the same way.
I have a working fix on a branch, not opened as a PR so as not to step on you: https://github.com/ash-project/ash/compare/main...grempe:ash:fix/invalid-page-options. It matches %Spark.Options.ValidationError{key: :page} in the else of those four functions and returns InvalidPage.exception(page: opts[:page]), and adds a non-list guard to page_opts/1. Full suite, format, credo, sobelow and dialyzer pass, and the tests in https://github.com/grempe/ash-fuzz-repros/blob/main/test/ash/invalid_page_options_test.exs all pass against it. Feel free to take it as a starting point, or if you have moved on, say so and I will open it.