close! fails because it does not have the aggregate open_issue_count loaded.
That means that the call-site code needs to know which fields need to be loaded before it can validate, and introducing new validations break existing code because they down know they need the fields loaded.
In my case the two related resources are not in the same data layer. I must admit my understanding of how the atomic validations work is still foggy, but I assume they are compiled down to SQL and executed in the Data Layer. Since one of my calculations fetches data from a git repo I assume atomic validations that won’t work?
Ah, then yes in that case you will need to load the data up front
You can avoid duplicative work by adding a change before the validation that loads the data. And you can also push validations off to before_action hooks:
Is there any reason why i wouldn’t do the load directly in the validation, like:
defmodule Validations.HasCommits do
use Ash.Resource.Validation
require Ash.Query
@impl true
def validate(changeset, _opts, _context) do
%{master_sha: sha} = Ash.load!(changeset.data, [:master_sha], lazy?: true, reuse_values?: true)
if sha == nil do
{:error, field: :base, message: "must have documents"}
else
:ok
end
end
@impl true
def atomic(changeset, opts, context) do
{:not_atomic, "This calculation uses git"}
end
end
I assume I have to set require_atomic? false on the action since it cannot be fully atomic anymore?