Skip to content

Inconsistency between empty_values and nil #4555

@josevalim

Description

@josevalim

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions