drikanius
I have a resource that uses pagination and also sort by inserted_at
Until version 2.18 it worked fine even using timestamps(). Currently I’m on master and I noticed that pagination only works properly when I use timestamps(private?: false)
I tried to create a test based on pagination_test.exs (from master)
defmodule Ash.Actions.PaginationTest do
use ExUnit.Case, async: true
require Ash.Query
defmodule Post do
@moduledoc false
use Ash.Resource, data_layer: Ash.DataLayer.Ets
ets do
private?(true)
end
attributes do
uuid_primary_key :id
attribute :user_id, :uuid
attribute :body, :string
timestamps()
end
actions do
defaults [:create, :update, :destroy]
read :read do
primary? true
pagination offset?: true, required?: true, default_limit: 25
end
read :read_and_sort do
pagination keyset?: true, required?: true, default_limit: 25
prepare build(sort: [inserted_at: :desc])
end
end
relationships do
belongs_to :user, Ash.Actions.PaginationTest.User, define_attribute?: false
end
end
defmodule User do
# same
end
defmodule Registry do
@moduledoc false
use Ash.Registry
entries do
entry User
entry Post
end
end
defmodule Api do
use Ash.Api
resources do
registry Registry
end
end
# ...
describe "testing timestamp sort" do
setup do
for i <- 0..9 do
user = Api.create!(Ash.Changeset.new(User, %{name: "#{i}"}))
if i != 0 do
for x <- 1..i do
Api.create!(Ash.Changeset.new(Post, %{body: "#{i}-#{x}", user_id: user.id}))
end
end
end
:ok
end
@tag :wip
test "todo" do
page = Ash.Query.for_read(Post, :read_and_sort) |> Api.read!(page: [limit: 1])
cursor = List.last(page.results).__metadata__.keyset
page_2 = Ash.Query.for_read(Post, :read_and_sort) |> Api.read!(page: [limit: 1, after: cursor])
dbg(page_2)
end
end
end
When calling the second read (using after and cursor) I got an error:
** (MatchError) no match of right hand side value: {#Ash.Query<resource: Ash.Actions.PaginationTest.Post, sort: [inserted_at: :desc, id: :asc], limit: 2, errors: [%Ash.Error.Query.NoSuchAttributeOrRelationship{attribute_or_relationship: :inserted_at, resource: Ash.Actions.PaginationTest.Post, changeset: nil, query: nil, error_context: [], vars: [], path: [:filter], stacktrace: #Stacktrace<>, class: :invalid}], select: [:id, :inserted_at, :user_id, :body, :updated_at]>, []}
code: page_2 = Ash.Query.for_read(Post, :read_and_sort) |> Api.read!(page: [limit: 1, after: cursor])
stacktrace:
(ash 2.18.1) lib/ash/actions/read/read.ex:352: anonymous fn/5 in Ash.Actions.Read.do_read/4
(ash 2.18.1) lib/ash/actions/read/read.ex:472: Ash.Actions.Read.maybe_in_transaction/3
(ash 2.18.1) lib/ash/actions/read/read.ex:200: Ash.Actions.Read.do_run/3
(ash 2.18.1) lib/ash/actions/read/read.ex:49: anonymous fn/3 in Ash.Actions.Read.run/3
(ash 2.18.1) lib/ash/actions/read/read.ex:48: Ash.Actions.Read.run/3
(ash 2.18.1) lib/ash/api/api.ex:2415: Ash.Api.read!/3
test/actions/pagination_test.exs:906: (test)
Observation:
- Does not use inserted_at to sort make the code works
- Uses
timestamps(private?: false), instead oftimestamps(), also make it works
Is this the expected behavior (using private?: false) or am I doing something wrong?
Trending in Questions
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
Hi everyone,
I am toying with the idea of building a “match maker” for giving personal help to people that wants to start coding.
I sta...
New
Hello,
I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
Documentation
While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
So my question is quite simple and i have found no conclusive answer on forum, google or AI.
Should we use :erlang.float for Integer to ...
New
I recently noticed that Elixir’s Logger defaults its primary log level to :debug when no :logger, :level application configuration is pre...
New
apply_graft/2 doesn’t rewrite an add_many sub-workflow’s deps on an add step. Grafted jobs cancel with “upstream job was deleted”
Version...
New
Other Trending Topics
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
Hi there! We created Gust: A task orchestrator inspired by Airflow.
For those who have never heard about Aiflow, it’s a Python-based wor...
New
Hi everyone!
The first release candidate for the Expert language server project is now available!
We’ve published a press release detai...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
With AI doing more of the implementation work, I’ve been wondering how much coding I should deliberately keep doing myself.
My main conc...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixirconf-us
- #ai
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #elixirconf-eu
- #metaprogramming
- #hex










Showing Posts 1 to 5- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
zachdaniel
Interesting…I’m not sure what the root issue might be, but I’ve pushed a fix for that specific stack trace that might allow us to gather some more information. We were using
left = rightin awithstatement, which was a typo as we meant to be usingleft <- right.drikanius
Well… after pull the error change at least. Still only works with private?: false
zachdaniel
Okay, try again
drikanius
Yay!!! Working
Thank you

zachdaniel
My pleasure! Thanks for the report