Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

List of atomics in validation results in a pattern match error #1194

Closed
danielatdpg opened this issue May 22, 2024 · 1 comment
Closed

List of atomics in validation results in a pattern match error #1194

danielatdpg opened this issue May 22, 2024 · 1 comment
Labels
bug Something isn't working needs review

Comments

@danielatdpg
Copy link
Contributor

Describe the bug
Hey, question, I've the following set of changes running for all actions

changes do
...
    change set_attribute(:publication_status, :published) do
      only_when_valid? true

      where [
        negate(attribute_equals(:published_at, nil)),
        compare(:published_at,
          greater_than_or_equal_to: &DateTime.utc_now/0
        )
      ]
    end
...

When running the primary update action for that resource I get this error

** (Ash.Error.Unknown) Unknown Error

     * %CaseClauseError{term: [{:atomic, [:published_at], {:_atomic_ref, :published_at} < ~U[2024-05-22 13:56:17.075341Z], error(Ash.Error.Changes.InvalidAttribute,  %{message: "must be greater than or equal to %{greater_than_or_equal_to}", value: {:_atomic_ref, :published_at}, vars: %{field: :published_at, greater_than_or_equal_to: ~U[2024-05-22 13:56:17.075346Z]}, field: :published_at})}]}
       (ash 3.0.2) lib/ash/changeset/changeset.ex:882: anonymous fn/4 in Ash.Changeset.atomic_condition/3
       (elixir 1.16.2) lib/enum.ex:4839: Enumerable.List.reduce/3
       (elixir 1.16.2) lib/enum.ex:2582: Enum.reduce_while/3
       (ash 3.0.2) lib/ash/changeset/changeset.ex:810: Ash.Changeset.run_atomic_change/3
       (ash 3.0.2) lib/ash/changeset/changeset.ex:693: anonymous fn/3 in ...

To Reproduce
Create a resource like this

defmodule A do
  use Ash.Resource,
    domain: As,
    data_layer: AshPostgres.DataLayer

  attributes do
    uuid_primary_key :id, writable?: true, public?: true

    attribute :publication_status, :atom do
      public? true
      allow_nil? false
      default :draft
    end

    attribute :published_at, :utc_datetime_usec, public?: true
 end
 
 changes do
    #See the change above
 end
end

Then run an update on a resource of type A

Expected behavior
The change should only be performed if the constraints for it are met

Runtime

  • Elixir version: 1.16.2
  • Erlang version: Erlang/OTP 26
  • OS: OSX 14.5 (23F79)
  • Ash version: 3.0.2
@danielatdpg danielatdpg added bug Something isn't working needs review labels May 22, 2024
danielatdpg added a commit to danielatdpg/ash that referenced this issue May 22, 2024
danielatdpg added a commit to danielatdpg/ash that referenced this issue May 22, 2024
@danielatdpg
Copy link
Contributor Author

Fixed by #1195

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs review
Projects
None yet
Development

No branches or pull requests

2 participants