Ash FrameworkAF
Ash Framework8mo ago
23 replies
lukasender

Change in how `Ash.Changeset.force_change_attributes` handles `nil` values?

i'm currently in the process of upgrading to the latest version. there seems to have been a change in how Ash.Changeset.force_change_attributes handles nil values?

at least, that what i seem to be observing.

here's a simple example:

%JdlEngine.Hubspot.Contact{} |> Ash.Changeset.for_update(:update, %{}) |> Ash.Changeset.force_change_attributes(%{ city: "vice city", }) - this then has the updated value in the attributes (see screenshot 1: attributes: %{city: "vice city"})

%JdlEngine.Hubspot.Contact{} |> Ash.Changeset.for_update(:update, %{}) |> Ash.Changeset.force_change_attributes(%{ city: nil, }) - this then has no updated values in attributes (see screenshot 2 - attributes: %{})

why is that important for me?

we implement our own data layer for hubspot resources and i have one use case where i want to forcefully overwrite data and even set attributes to nil if that should be the case.

in the data layer implementation i'm currently relying on attributes to detect what attributes i need to update on hubspot. see screenshot 3, the cast_changeset-implementation where i use attributes to then build a map of changes. maybe that is the wrong approach entirely and i should change that, but that behaviour seems to have changed now since the attributes will not contain the e.g. city: nil anymore.
image.png
image.png
image.png
Was this page helpful?