You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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?
The text was updated successfully, but these errors were encountered:
I think for arrays we are removing entries that match empty values rather than turning them into nil. So if we go with this change we probably have to make the two behaviours consistent?
The current behaviours seem aligned to me since changing it to the default value is basically like removing an explicitly given change.
In terms of making the change or not, I don't really have use cases to fall back on. I can only say it seems theoretically useful to have both behaviours. Maybe some situations you want to treat values as if they are nil and some situations you want to treat them like they were not given.
Actually sorry I had a misunderstanding. I thought empty_values erased the change so that if the value didn't previously exist it saves to the default. But it makes it an explicit change to the default.
Then I think treating it like nil is a lot more intuitive. But still wondering if the current array behaviour is inconsistent with that.
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 benil
). However, if you passnil
, it always sets it asnil
.Expected behavior
In my mind,
empty_values
should behave the exact same asnil
, 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 thatempty_values
andnil
behave the same. One suggestion is to deprecateempty_values
in favor ofnil_values
, which accept the same configuration, but behave as nil.Thoughts?
The text was updated successfully, but these errors were encountered: