# Default value of `attrs` of `Context.update_*`?

I am using `mix phx.gen.html`, and I noticed following code:

``````  def create_tag(attrs \\ %{}) do
%Tag{}
|> Tag.changeset(attrs)
|> Repo.insert()
end

def update_tag(%Tag{} = tag, attrs) do
tag
|> Tag.changeset(attrs)
|> Repo.update()
end

def change_tag(%Tag{} = tag, attrs \\ %{}) do
Tag.changeset(tag, attrs)
end
``````

`attrs` argument of `create_tag` and `change_tag` has a default value `%{}`.

But, `attrs` argument of `update_tag` doesn’t. Why doesn’t it have the default value ? Is it removed on purpose?

1 Like

Creating an entity without explicit user input it something, which you might want to allow. Your entity/changeset might be able to supply enough defaults for it to be created. But updating without something to update doesn’t really make sense – at least not if your `update_*` is a “pure” function without pulling changes in via some side-effects.

1 Like