Skip to content

Commit

Permalink
fix: empty milliseconds for utc datetime must have precision 6
Browse files Browse the repository at this point in the history
fix: ensure actor & authorize? contexts are set even if not provided
  • Loading branch information
zachdaniel committed Dec 19, 2023
1 parent 867c786 commit ff1a590
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/ash/actions/helpers.ex
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,11 @@ defmodule Ash.Actions.Helpers do
context = Process.get(:ash_context, %{}) || %{}
private_context = Map.new(Keyword.take(opts, [:actor, :authorize?]))

context = Map.merge(context, private_context)
context =
context
|> Map.merge(private_context)
|> Map.put_new(:actor, nil)
|> Map.put_new(:authorize?, false)

case query_or_changeset do
%{__struct__: Ash.ActionInput} ->
Expand Down
14 changes: 14 additions & 0 deletions lib/ash/type/datetime.ex
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,20 @@ defmodule Ash.Type.DateTime do
cast_input(%{datetime | microsecond: {0, 0}}, constraints)
end

def cast_input(
%DateTime{microsecond: {0, 0}} = datetime,
[{:precision, :microsecond} | _] = constraints
) do
cast_input(%{datetime | microsecond: {0, 6}}, constraints)
end

def cast_input(
%DateTime{microsecond: nil} = datetime,
[{:precision, :microsecond} | _] = constraints
) do
cast_input(%{datetime | microsecond: {0, 6}}, constraints)
end

def cast_input(value, constraints) do
Ecto.Type.cast(storage_type(constraints), value)
end
Expand Down

0 comments on commit ff1a590

Please sign in to comment.