fix: allow_nil?: false + default interaction

This commit is contained in:
Zach Daniel 2021-03-14 23:06:18 -04:00
parent a33e0b97b9
commit f6026c6895
2 changed files with 4 additions and 3 deletions

View file

@ -706,7 +706,7 @@ defmodule Ash.Changeset do
Enum.reduce(attributes, changeset, fn required_attribute, changeset ->
if Ash.Changeset.changing_attribute?(changeset, required_attribute.name) ||
required_attribute.default do
not is_nil(required_attribute.default) do
changeset
else
Ash.Changeset.add_error(
@ -730,8 +730,7 @@ defmodule Ash.Changeset do
end
Enum.reduce(attributes, changeset, fn required_attribute, changeset ->
if Ash.Changeset.changing_attribute?(changeset, required_attribute.name) ||
required_attribute.default do
if Ash.Changeset.changing_attribute?(changeset, required_attribute.name) do
if get_attribute(changeset, required_attribute.name) do
changeset
else

View file

@ -155,6 +155,8 @@ defmodule Ash.Test.Actions.CreateTest do
attribute(:list_attribute, {:array, :integer})
attribute(:date, :date)
attribute(:binary, :binary)
attribute(:required_with_default, :string, allow_nil?: false, default: "string")
attribute(:required_boolean_with_default, :boolean, allow_nil?: false, default: false)
attribute(:list_attribute_with_constraints, {:array, :integer},
constraints: [