Loading nested resource encrypted fields crashes ash_postgres
I have these resources:
When I fetch my offers and try to load the offeror name, ash_postgres will crash:
defmodule Marketplace.Markets.Property.Offer do
...
relationships do
belongs_to :offeror, Offeror, allow_nil?: false
end
end
defmodule Marketplace.Markets.Property.Offeror do
@moduledoc false
alias Marketplace.Markets
use Ash.Resource,
data_layer: AshPostgres.DataLayer
attributes do
uuid_primary_key :id
attribute :email, :ci_string, allow_nil?: false
attribute :encrypted_phone_number, :binary, allow_nil?: false, private?: true
attribute :encrypted_first_name, :binary, allow_nil?: false, private?: true
attribute :encrypted_surname, :binary, allow_nil?: false, private?: true
end
calculations do
alias Marketplace.Ash.Calculations.Decrypt
calculate :phone_number, :string, {Decrypt, field: :encrypted_phone_number}
calculate :first_name, :string, {Decrypt, field: :encrypted_first_name}
calculate :surname, :string, {Decrypt, field: :encrypted_surname}
end
relationships do
has_one :offer, Markets.Property.Offer
end
postgres do
table "users"
repo Marketplace.Repo
migrate? false
end
actions do
defaults [:read]
end
enddefmodule Marketplace.Markets.Property.Offer do
...
relationships do
belongs_to :offeror, Offeror, allow_nil?: false
end
end
defmodule Marketplace.Markets.Property.Offeror do
@moduledoc false
alias Marketplace.Markets
use Ash.Resource,
data_layer: AshPostgres.DataLayer
attributes do
uuid_primary_key :id
attribute :email, :ci_string, allow_nil?: false
attribute :encrypted_phone_number, :binary, allow_nil?: false, private?: true
attribute :encrypted_first_name, :binary, allow_nil?: false, private?: true
attribute :encrypted_surname, :binary, allow_nil?: false, private?: true
end
calculations do
alias Marketplace.Ash.Calculations.Decrypt
calculate :phone_number, :string, {Decrypt, field: :encrypted_phone_number}
calculate :first_name, :string, {Decrypt, field: :encrypted_first_name}
calculate :surname, :string, {Decrypt, field: :encrypted_surname}
end
relationships do
has_one :offer, Markets.Property.Offer
end
postgres do
table "users"
repo Marketplace.Repo
migrate? false
end
actions do
defaults [:read]
end
endWhen I fetch my offers and try to load the offeror name, ash_postgres will crash:
[offer] = Marketplace.Markets.read! Marketplace.Markets.Property.Offer
Marketplace.Markets.load(offer, [offeror: [:first_name, :surname]])[offer] = Marketplace.Markets.read! Marketplace.Markets.Property.Offer
Marketplace.Markets.load(offer, [offeror: [:first_name, :surname]])