nil as arg(:organization_id) and arg(:school_id) in this case.Ash.Query ignored the parenthesis in this part of the expression (shared? == :organization and organization_id == ^arg(:organization_id)) since if you remove it, then the generated where expression makes sense.