Weird issue using changeSet with boolean field set to false

I have a weird issue in Ecto with boolean field in changeSets. Suppose I have:

def changeset(%MyTable{} = table, attrs) do
    table
    |> change(attrs)
end

Then the following

%MyTable{id: id}
|> MyTable.changeset({my_boolean?: true})

produces a valid changeset where the field my_boolean? is set to true. But the following:

%MyTable{id: id}
|> MyTable.changeset({my_boolean?: false})

produces a valid empty changeset. Like that I would say that it seems to be a bug. Maybe
if map[field] ... is used somewhere in the code to check if field is a field of map (instead of using if map[field] != nil). Maybe I miss something and it is not a bug.

Anyone knows what I can do to be able to create ChangeSets with boolean fields set to false ?

So my problem comes from the fact that the field my_boolean has default: false in the schema.

2 Likes