params icon indicating copy to clipboard operation
params copied to clipboard

don't remove empty string

Open exoconnor opened this issue 7 years ago • 1 comments

This is a mildly breaking change, but is also what I assumed default behavior would be, curious what others think.

With current cast behaviour, if an empty string is sent as a param, that string gets removed, due to default empty values behaviour https://hexdocs.pm/ecto/Ecto.Changeset.html#module-empty-values

If I want to clear a text field, I typically send a json object of the form

{ field-to-clear: ""}

This is getting changed to nil, and I can't clear fields.

I could set default empty string, but there's only one update route, and other actions will send an object of form

{ other-field: 55 }

And with default empty string, this unrelated update zeroes out my text field.

This update is all that's necessary to get my narrow use case working, I haven't dug too hard into potential consequences elsewhere.

Requires ecto version bump to pass tests.

Also leaving internet as soon as I post this, so not going to be a good conversationalist for a couple days.

exoconnor avatar Aug 23 '18 20:08 exoconnor

Looks like something reasonable to me. Could you please also add a test to your PR?

I'm just not using this package right now. So I hope someone can give it a try and see if we should bump a major version or something.

vic avatar Sep 11 '18 19:09 vic