{"action":"created","issue":{"url":"https://api.github.com/repos/elixir-ecto/ecto/issues/1684","repository_url":"https://api.github.com/repos/elixir-ecto/ecto","labels_url":"https://api.github.com/repos/elixir-ecto/ecto/issues/1684/labels{/name}","comments_url":"https://api.github.com/repos/elixir-ecto/ecto/issues/1684/comments","events_url":"https://api.github.com/repos/elixir-ecto/ecto/issues/1684/events","html_url":"https://github.com/elixir-ecto/ecto/issues/1684","id":176518783,"number":1684,"title":"Casting empty strings is broken","user":{"login":"stavro","id":2391584,"avatar_url":"https://avatars.githubusercontent.com/u/2391584?v=3","gravatar_id":"","url":"https://api.github.com/users/stavro","html_url":"https://github.com/stavro","followers_url":"https://api.github.com/users/stavro/followers","following_url":"https://api.github.com/users/stavro/following{/other_user}","gists_url":"https://api.github.com/users/stavro/gists{/gist_id}","starred_url":"https://api.github.com/users/stavro/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/stavro/subscriptions","organizations_url":"https://api.github.com/users/stavro/orgs","repos_url":"https://api.github.com/users/stavro/repos","events_url":"https://api.github.com/users/stavro/events{/privacy}","received_events_url":"https://api.github.com/users/stavro/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2016-09-13T00:28:57Z","updated_at":"2016-09-13T06:55:42Z","closed_at":null,"body":"### Environment\r\n\r\n* Elixir version: 1.3.0\r\n* Ecto version: **latest@master** (currently ref: `5222d528879c2671daa7230f275bed3818a51278`)\r\n* Operating system: OS X\r\n\r\n### Current behavior\r\n\r\nAn empty string and `nil` are not equivalent, however Ecto currently silently transforms empty strings into `nil`.\r\n\r\n```elixir\r\ndefmodule User do\r\n  use Ecto.Schema\r\n  import Ecto.Changeset\r\n\r\n  schema \"users\" do\r\n    field :name, :string\r\n  end\r\n\r\n  def update(data, params) do\r\n    data\r\n    |> cast(params, ~w(name))\r\n  end\r\nend\r\n\r\nchangeset_1 =\r\n  %User{name: \"\"}\r\n  |> User.update(%{name: \"\"})\r\n\r\nIO.inspect(changeset.changes) #=> %{name: nil}\r\n\r\nchangeset_2 =\r\n  %User{name: \"Sean\"}\r\n  |> User.update(%{name: \"\"})\r\n\r\nIO.inspect(changeset.changes) #=> %{name: nil}\r\n```\r\n\r\n### Expected behavior\r\n\r\nThere should be no changes in `changeset_1`, and the result should be an empty string and not a nil value in `changeset_2` above.\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/elixir-ecto/ecto/issues/comments/246592039","html_url":"https://github.com/elixir-ecto/ecto/issues/1684#issuecomment-246592039","issue_url":"https://api.github.com/repos/elixir-ecto/ecto/issues/1684","id":246592039,"user":{"login":"josevalim","id":9582,"avatar_url":"https://avatars.githubusercontent.com/u/9582?v=3","gravatar_id":"","url":"https://api.github.com/users/josevalim","html_url":"https://github.com/josevalim","followers_url":"https://api.github.com/users/josevalim/followers","following_url":"https://api.github.com/users/josevalim/following{/other_user}","gists_url":"https://api.github.com/users/josevalim/gists{/gist_id}","starred_url":"https://api.github.com/users/josevalim/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/josevalim/subscriptions","organizations_url":"https://api.github.com/users/josevalim/orgs","repos_url":"https://api.github.com/users/josevalim/repos","events_url":"https://api.github.com/users/josevalim/events{/privacy}","received_events_url":"https://api.github.com/users/josevalim/received_events","type":"User","site_admin":false},"created_at":"2016-09-13T06:55:42Z","updated_at":"2016-09-13T06:55:42Z","body":"@stavro Ecto 2.0 introduced something called :empty_values where some values are automatically cast to their default value. For example, if you set `field :name, :string, default: \"\"`, the value should then always be cast to an empty string when an empty value is found."}}
{"actor":{"display_login":"josevalim"}}