-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Open
Labels
Description
Elixir version
All
Database and Version
All
Ecto Versions
v3.12
Database Adapter and Versions (postgrex, myxql, etc)
All
Current behavior
Today there is some slight inconsistency between empty values and nil. When you pass an empty string to Ecto.Changeset.cast
, it defaults to the field default value (which may not be nil
). However, if you pass nil
, it always sets it as nil
.
Expected behavior
In my mind, empty_values
should behave the exact same as nil
, which is to set the field to nil.
On the other hand, we may have non-nullable fields in the future (it will be a type system requirement), so setting the field to nil
should either be a cast error or rely on the default value. The important though is that empty_values
and nil
behave the same. One suggestion is to deprecate empty_values
in favor of nil_values
, which accept the same configuration, but behave as nil.
Thoughts?