Sorry for the slow response @zachdaniel … went in a changed test.dev to include level: :debug and now I’m getting this:
18:43:07.899 [debug] QUERY OK source="teams" db=0.5ms
SELECT DISTINCT ON (t0."id") t0."id", t0."name", t0."updated_at", t0."inserted_at" FROM "teams" AS t0 LEFT OUTER JOIN "public"."team_members" AS t1 ON t0."id" = t1."team_id" LEFT OUTER JOIN "public"."users" AS u2 ON u2."id" = t1."user_id" WHERE (t0."id"::uuid = $1::uuid) AND (exists((SELECT 1 FROM "public"."users" AS su0 INNER JOIN "public"."team_members" AS st1 ON (st1."user_id" = su0."id") AND (t0."id" = st1."team_id") WHERE (su0."id"::uuid = $2::uuid)))) LIMIT $3 ["5520e3d0-4821-42b2-a6af-7b49f186cad3", "f265eaf9-8786-4632-a5b6-b99d39c0fe46", 1]
18:43:07.899 [debug] QUERY OK db=0.1ms
begin []
18:43:07.900 [debug] QUERY OK source="teams" db=0.3ms
SELECT DISTINCT ON (t0."id") t0."id" FROM "teams" AS t0 LEFT OUTER JOIN "public"."team_members" AS t1 ON t0."id" = t1."team_id" WHERE (exists((SELECT 1 FROM "public"."team_members" AS st0 WHERE (st0."user_id"::uuid = $1::uuid) AND (t0."id" = st0."team_id")))) AND (t0."id"::uuid = $2::uuid) ["f265eaf9-8786-4632-a5b6-b99d39c0fe46", "5520e3d0-4821-42b2-a6af-7b49f186cad3"]
18:43:07.900 [debug] WasteWalk.Accounts.User.read: skipped query run due to filter being false"
18:43:07.900 [debug] QUERY OK db=0.2ms
rollback []
remove_team_member() call ->: {:error,
%Ash.Error.Invalid{
errors: [
%Ash.Error.Changes.InvalidRelationship{
relationship: :team_members,
message: "changes would create a new related record",
splode: Ash.Error,
bread_crumbs: [],
vars: [],
path: [],
stacktrace: #Splode.Stacktrace<>,
class: :invalid
}
]
}}
1) test teams must only allow team leads to manage membership (WasteWalk.Teams.TeamTest)
test/waste_walk/teams/team_test.exs:99
** (MatchError) no match of right hand side value: {:error, %Ash.Error.Invalid{errors: [%Ash.Error.Changes.InvalidRelationship{relationship: :team_members, message: "changes would create a new related record", splode: Ash.Error, bread_crumbs: [], vars: [], path: [], stacktrace: #Splode.Stacktrace<>, class: :invalid}]}}
code: {:ok, _} = WasteWalk.Teams.remove_team_member(team.id, context.new_team_member.id, actor: context.new_team_lead)
stacktrace:
test/waste_walk/teams/team_test.exs:116: (test)
I added a few IO.inspect() messages to help clarify.
First thing that jumps out at me is the “skipped query run due to filter being false,” which is a bit odd… keep in mind that the custom function (above) works just fine and as far as I can tell, they should be doing very nearly the same thing.
Just to see what would happen, I added:
bypass do
authorize_if always()
end
At the top of the policies block on both Team and Members and it made no difference. (Well, it broke a bunch of other tests… but this test still fails in exactly the same way).
So I don’t think it’s actually authorization related. Maybe. ![]()
(Actually, now I’m really curious if you would write the custom function in the same way…)






















