Closed moxley closed 4 months ago
Any modifications of attributes that happen before the call to build the changeset for an action are treated as potentially from input. This is by design although it can be inconvenient at times. The changeset must be first validated for the action, and then attributes can be force changed ( or it can be done in hooks).
Ah yes, I got that backwards. Thanks!
Describe the bug
For private attributes, I'm not able to create a valid changeset to change the attribute value.
The documentation says that the
:public?
option of theattribute
DSL only affects public interfaces, such asAshGraphql
andAshJsonApi
: https://hexdocs.pm/ash/sensitive-data.html#public-private-attributes. But theAsh.Changeset
module doesn't appear to be a public interface in the sense implied by the documentation.Additionally, the documentation seems to apply the
:public?
option only affects reads, not writes, soforce_change_attribute()
shouldn't be required anyway.To Reproduce
As demonstrated in this modification of ash's ChangesetTest: https://github.com/moxley/ash/commit/439d8267e2330a00b4144838abd465647cf79ba7
Ash.Changeset.force_change_attribute()
to set the attribute's valueAsh.Changeset.for_create()
.%Ash.Error.Changes.InvalidAttribute{message: "Cannot be changed"}
.Expected behavior
The attribute is changed, and the changeset is valid.
Runtime
main
Additional context Add any other context about the problem here.