`prepare build(sort: [id: :asc])` sometimes not sorted?!?!

Really feel like I’m seeing 1+1 == maybe(2) here… (or just not seeing something obvious; I must be using prepare build wrong)…

I have a resource Stereotype with an integer id:

attributes do
  integer_primary_key :id
  ...

And it has a get_all function that should always sort on id:

actions do
  read :get_all do
    prepare build(sort: [id: :asc])
  end
  ...

And I’m checking that it does with a little test…

def sorted_ascending?(list) do
  ids = Enum.map(list, & &1.id)
  |> IO.inspect(label: "unsorted list")
  ids == Enum.sort(ids)
  |> IO.inspect(label: "sorted list")
end

test "is sorted on id by default", context do
  {:ok, list} = WasteWalk.Activities.Stereotype.get_all()
  assert sorted_ascending?(list)
end

And the test fails every now and again… like, maybe every 10 or so times I run my test suite, I’ll see it fail once…

unsorted list: [14324, 14320, 14321, 14322, 14323, 14325, 14326, 14327, 14328, 14329, 14330, 14331, 14332, 14333]
sorted list: [14320, 14321, 14322, 14323, 14324, 14325, 14326, 14327, 14328, 14329, 14330, 14331, 14332, 14333]

  1) test stereotypes sort on id by default (WasteWalk.Activities.StereotypeTest)
     test/waste_walk/activities/stereotype_test.exs:46
     Expected truthy, got false
     code: assert sorted_ascending?(list)

…?

What does the SQL query look like in the logs?

What does the code interface definition look like?

Ahhh. Thanks @zachdaniel … what I wouldn’t give for an AI that was smart enough to be all, “did you check your code interface?”

So, ya… Code interface:

  code_interface do
    define :new, args: [:name, :hint, :type, :phase], action: :create
    define :get_all, action: :read
    define :get_by_id, action: :read, get_by: [:id]
  end

should be calling :get_all not :read.
:melting_face: