Why would :invalid be passed to cast/4 as param?

I’ve been reading Ecto.changeset and trying to figure out how cast/4 works. I’ve come across with this definition of cast/6 which accepts :invalid as a param:

I was thinking maybe it’s the return value of a function but in tests :invalid is just passed as a param as well.

I couldn’t really figure out why :invalid would be passed as a param. What’s the use case here?

Digging around in the history of cast had some interesting results. The option has been spelled :invalid, :empty, nil, and %{} at various points:

4 Likes

So as far as I understood it was just a default option for params, if you wanted a default you could use :invalid.
By the way could you please tell me how you’ve gone about searching for this? I’ve tried git blame but couldn’t really find anything useful. I’d really appreciate it.

The basic git blame loses effectiveness when the changes happened a long time ago. But Github adds some UI that helps dig “backwards” through history in the “Blame” view:

Screen Shot 2021-07-17 at 6.14.59 PM

The button helps, but you’ll still need to manually track where the “thing” you’re investigating is in each change (for instance, cast changed arity several times and switched back and forth between matching :invalid and :empty)

Another tool that can be useful if the thing you’re looking for is mentioned infrequently in code and/or commit messages is the “pickaxe” (git log -S) to search through history. The atom :invalid is a little too common in the source for that approach to work efficiently here.

4 Likes