Skip to content

Temporal entity attributes are validated by struct name and nothing else #1184

Description

@bartblast

A :date, :datetime or :time value is checked by asking whether it's the right struct. Nothing looks at the fields, so a value no calendar has passes:

%Date{year: 2026, month: 13, day: 40}   -> accepted
Date.new(2026, 13, 40)                  -> {:error, :invalid_date}

Date.new/3 won't build one, but a struct literal will, and so will a map update on a date you already have. Neither is unusual code.

What happens after it's accepted depends on which way it goes, and none of it is good. A date gets spelled onto the wire as "2026-13-40", which the framework then refuses to read back. A datetime or a time doesn't even get that far and raises a FunctionClauseError from inside Calendar.ISO. A write that reaches Postgres dies the same way, in the driver, with nothing in the message about the attribute or the entity or the value. On the browser side an optimistic write renders before any of that, so the page just shows the bad date.

A value the framework accepts should be one Elixir itself calls a date.

There's a smaller thing downstream of this. The client rebuilds these structs from the wire, and since #1182 it refuses an impossible time while still accepting an impossible date or datetime, so the three don't agree with each other any more.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions