drikanius

drikanius

Unknown Error (OriginalDataNotAvailable) when trying to create a update

Hi guys.

I have this module, and I’m just trying to create an update:

defmodule Marketplace.Ap.Appointment do
  @moduledoc false

  alias Marketplace.Ap

  use Ash.Resource,
    data_layer: AshPostgres.DataLayer

  code_interface do
    define_for Marketplace.Ap

    define :create
    define :update

    define :get_by_lead
  end

  attributes do
    uuid_primary_key :id

    attribute :appt_type, :integer do
      description "In-Home = 1, Virtual = 2"
    end

    attribute :appointment_time, :utc_datetime_usec

    attribute :status, :string
    attribute :name_assigned_to, :string

    attribute :reschedule_uri, :string

    attribute :cancel_uri, :string
    attribute :cancel_reason, :string
    attribute :cancel_notes, :string

    attribute :cancel_by_type, :string

    attribute :score, :integer, allow_nil?: false

    timestamps()
  end

  relationships do
    belongs_to :canceled_by, Ap.User
    belongs_to :assigned_to, Ap.User

    belongs_to :assigned_by, Ap.User do
      primary_key? true
      allow_nil? false
      attribute_writable? true
    end

    belongs_to :lead, Ap.Lead do
      attribute_writable? true
    end
  end

  identities do
    identity :unique_id, [:lead_id]
  end

  postgres do
    table "appointment"

    schema "dbo"

    repo Marketplace.ApRepo
  end

  actions do
    alias Marketplace.Ap.Actions.Appointment.Actions.Create

    defaults [:read, :update]

    create :create do
      primary? true

      accept [:score]

      upsert? true
      upsert_fields [:score, :updated_at, :appt_type]
      upsert_identity :unique_id

      argument :lead_id, :uuid, allow_nil?: false
      argument :appt_type, :atom, allow_nil?: false

      change Create.Changes.FixApptType

      change set_attribute(:assigned_by_id, actor(:id))
      change set_attribute(:lead_id, arg(:lead_id))
    end

    read :get_by_lead do
      description "get appointment based on lead"

      argument :lead_id, :uuid, allow_nil?: false

      get? true

      filter expr(lead_id == ^arg(:lead_id))
    end
  end
end

However, when I try to access using iex:
[appt] = Marketplace.Ap.Appointment |> Marketplace.Ap.read!
Marketplace.Ap.Appointment.update(appt, %{cancel_notes: "hi"})

I end up with this error:

** (Ash.Error.Unknown) Unknown Error

* ** (KeyError) key :__meta__ not found in: %Ash.Changeset.OriginalDataNotAvailable{reason: :atomic_query_update}
  :erlang.map_get(:__meta__, %Ash.Changeset.OriginalDataNotAvailable{reason: :atomic_query_update})
  (elixir 1.16.0) lib/map.ex:318: Map.update!/3
  (ash_postgres 1.4.0) lib/data_layer.ex:1257: AshPostgres.DataLayer.update_query/4
  (ash 2.18.1) lib/ash/actions/update/bulk.ex:278: Ash.Actions.Update.Bulk.do_atomic_update/4
  (ash 2.18.1) lib/ash/actions/update/bulk.ex:120: Ash.Actions.Update.Bulk.run/5
  (ash 2.18.1) lib/ash/actions/update/update.ex:81: Ash.Actions.Update.run/4
  (marketplace 1.19.0) lib/marketplace/ap.ex:1: Marketplace.Ap.update/2
  (stdlib 5.0.2) erl_eval.erl:746: :erl_eval.do_apply/7
  (elixir 1.16.0) src/elixir.erl:378: :elixir.eval_forms/4
  (elixir 1.16.0) lib/module/parallel_checker.ex:112: Module.ParallelChecker.verify/1
  (iex 1.16.0) lib/iex/evaluator.ex:331: IEx.Evaluator.eval_and_inspect/3
  (iex 1.16.0) lib/iex/evaluator.ex:305: IEx.Evaluator.eval_and_inspect_parsed/3
  (iex 1.16.0) lib/iex/evaluator.ex:294: IEx.Evaluator.parse_eval_inspect/4
  (iex 1.16.0) lib/iex/evaluator.ex:187: IEx.Evaluator.loop/1
  (iex 1.16.0) lib/iex/evaluator.ex:32: IEx.Evaluator.init/5
  (stdlib 5.0.2) proc_lib.erl:241: :proc_lib.init_p_do_apply/3
    :erlang.map_get(:__meta__, %Ash.Changeset.OriginalDataNotAvailable{reason: :atomic_query_update})
    (elixir 1.16.0) lib/map.ex:318: Map.update!/3
    (ash_postgres 1.4.0) lib/data_layer.ex:1257: AshPostgres.DataLayer.update_query/4
    (ash 2.18.1) lib/ash/actions/update/bulk.ex:278: Ash.Actions.Update.Bulk.do_atomic_update/4
    (ash 2.18.1) lib/ash/actions/update/bulk.ex:120: Ash.Actions.Update.Bulk.run/5
    (ash 2.18.1) lib/ash/actions/update/update.ex:81: Ash.Actions.Update.run/4
    (marketplace 1.19.0) lib/marketplace/ap.ex:1: Marketplace.Ap.update/2

Would anyone have any ideas on how to fix this?

Marked As Solved

zachdaniel

zachdaniel

Creator of Ash

okay, tried another thing :slight_smile:

Also Liked

zachdaniel

zachdaniel

Creator of Ash
zachdaniel

zachdaniel

Creator of Ash

:partying_face: thanks for the kind words :bowing_man:

Where Next?

Popular in Questions Top

sen
Hi All, I set a environment variables in dev.exs , like below code. when i start server, how can i set the ${enable} value? thanks. d...
New
nobody
How to bind a phoenix app to a specific ip address? could not find anything about that, nowhere, unfortunately, but for me this is quite...
New
Darmani72
If I have a post route which an argument: post /my_post_route/:my_param1, MyController.my_post_handler How would get the post params ...
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
script
If I have a string “1000 cfu/ml” . I want to remove the characters and / and space . So the string is like this "1000" What is the ...
New
Brian
What is the proper way to load a module from a file in to IEX? In the python world, doing something like this pretty standard: from ....
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
jononomo
For some reason my phoenix channels are working for me in my local dev environment, but as soon as I deploy via Docker, I get a 403 error...
New
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New

Other popular topics Top

aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New
baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
New
Nvim
Anybody knows a comprehensive comparison of Django and Phoenix, thanks for the help. Where are they similar? Where do they differ the m...
New
ovidiubadita
Hey all, I discovered Elixir and I love it. I always wanted to learn a functional programming and I intended to go for Haskell, but afte...
New
chrismccord
This release brings a number of exciting features, including integration with the new Phoenix LiveDashboard and Phoenix LiveView. There h...
New
josevalim
Hi everyone, One of the features added to Elixir early on to help integration with Erlang code was the idea of overridable function defi...
New
freewebwithme
Using vs code and installed ElixirLS: support and debugger. And I got an error popped up on start up says Failed to run ‘elixir’ comma...
New
aesmail
Hello guys, I have finally made it. I created an admin interface for a framework. It’s been on my todo list for years and with the curre...
New
openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New

Latest on Elixir Forum

Elixir Forum

We're in Beta

About us Mission Statement