SKIP LOCKED lock fails in Ash.Query

I have this Ash.Query in my code:

        CronJob
        |> Ash.Query.for_read(:due)
        |> Ash.Query.lock("FOR UPDATE SKIP LOCKED")
        |> Ash.read(authorize?: false)

When I run it, I get this error:

{:error,
 %Ash.Error.Invalid{
   errors: [
     %Ash.Error.Query.LockNotSupported{
       resource: Core.Jobs.CronJob,
       lock_type: "FOR UPDATE SKIP LOCKED",
       splode: Ash.Error,
       bread_crumbs: [],
       vars: [],
       path: [],
       stacktrace: #Splode.Stacktrace<>,
       class: :invalid
     }
   ]
 }}

But looking at AshPostgres code, it clearly has support for it here: ash_postgres/lib/data_layer.ex at f15ddb24948f81cf36bd89048b68ada8936fb8d1 · ash-project/ash_postgres · GitHub

Why is this failing? Shouldn’t it just work since AshPostgres has support for it?

Found the issue, the can? function is returning false when it shouldn’t, that’s a bug, so I created an issue here Locks are not correctly verified in `can?` function · Issue #703 · ash-project/ash_postgres · GitHub

1 Like