warning: Changeset has already been validated for action :create.

I am getting this warning when trying to set an attribute before submitting a form, since this isn't user provided and I don't want to make the http call if this isn't going to be submitted, is there maybe another way to accomplish this as the warning says this will be an error in the future.
case AshPhoenix.Form.submit(socket.assigns.form,
params: params,
before_submit: fn changeset ->
{:ok, %{body: %{"id" => stripe_customer_id}}} = QueryDesk.Stripe.create_customer()

changeset
|> Ash.Changeset.change_attribute(:stripe_customer_id, stripe_customer_id)
|> Ash.Changeset.manage_relationship(
:users,
[socket.assigns.current_user],
type: :append_and_remove
)
end
) do
case AshPhoenix.Form.submit(socket.assigns.form,
params: params,
before_submit: fn changeset ->
{:ok, %{body: %{"id" => stripe_customer_id}}} = QueryDesk.Stripe.create_customer()

changeset
|> Ash.Changeset.change_attribute(:stripe_customer_id, stripe_customer_id)
|> Ash.Changeset.manage_relationship(
:users,
[socket.assigns.current_user],
type: :append_and_remove
)
end
) do
12 Replies
dblack
dblack2y ago
You could push this up to the resource with a default MFA. default MFAs (i'm pretty sure) only get called on submit https://ash-hq.org/docs/dsl/ash-resource#attributes-attribute-default
michaelst
michaelstOP2y ago
ooooh
dblack
dblack2y ago
yeah i'd wait for confirmation on that!
ZachDaniel
ZachDaniel2y ago
You are correct
dblack
dblack2y ago
sweet
ZachDaniel
ZachDaniel2y ago
In this specific case, that warning is letting you know that you're using change_attribute but you've already validated the changeset. Its just informative. To get around it, you should use force_change_attribute
dblack
dblack2y ago
nice
ZachDaniel
ZachDaniel2y ago
Its to prevent you from accidentally bypassing a validation on the resource
michaelst
michaelstOP2y ago
oh from the docs force just allows you to change a nonwritable attribute didn't think it would apply in this case since it is a writable attribute
ZachDaniel
ZachDaniel2y ago
Yeah, we should probably add a snippet there
michaelst
michaelstOP2y ago
I like the default better though, thanks!
ZachDaniel
ZachDaniel2y ago
It does both essentially

Did you find this page helpful?