Skip to content

Nested Map causes non-default updates to fail with Jason encoder error #60

@thenoahhein

Description

@thenoahhein

Describe the bug
If you have a map that has array's of maps e.g.

    summary: %{
      chat_history: [
        %{"content" => "Default system prompt", "role" => "system"},
        %{
          "content" =>
            "Here's a collection of tweets from the Twitter list 'Web 3 Mid':\nTweet by KhanAbbas201 (2024-08-26 19:40:13.000000Z):\n@Rahatcodes told me I look good wearing the Eth shirt. https://t.co/xBugAt2tDi\nTweet by Rahatcodes (2024-08-26 19:42:55.000000Z):\n@KhanAbbas201 I dont recall saying this\nTweet by KhanAbbas201 (2024-08-26 19:44:08.000000Z):\n@Rahatcodes Damn what happened to your memory bruv?\nTweet by angelinarusse (2024-08-26 19:56:05.000000Z):\n@dabit3 Real degens call it Twitter\nTweet by angelinarusse (2024-08-26 20:13:58.000000Z):\n@hamseth They tried the same in Afghanistan and it didn’t go well for them.\nTweet by KhanAbbas201 (2024-08-26 20:39:53.000000Z):\nTweet by Osh_mahajan (2024-08-26 21:34:08.000000Z):\n@FedericoNoemie 🐾🐾🦘\nTweet by developer_dao (2024-08-26 21:39:59.000000Z):\n@ZwigoZwitscher @ArweaveEco @k4yls Wildly high praise, ty ty. @k4yls is 🔥 with a 🐶\nTweet by developer_dao (2024-08-26 21:41:17.000000Z):\nRT @ZwigoZwitscher : I've been into @ArweaveEco for years – as an interested outsider – and still learned new things in that course 👇. Thanks…\nTweet by angelin...eet by developer_dao (2024-08-26 22:18:09.000000Z):\nRT @jeremykauffman: BREAKING: France has arrested Gonzalve Bich, the CEO of Bic\nTweet by PatrickAlphaC (2024-08-26 22:26:16.000000Z):\n@oxfav @ar_io_network\n",
          "role" => "user"
        },
        %{"content" => "test", "role" => "user"},
        %{
          "content" => "It looks like you're testing the feature. How can I assist you further?",
          "role" => "assistant"
        }
      ]
    }

To Reproduce
A minimal set of resource definitions and calls that can reproduce the bug.

pull down: https://github.com/nheingit/ash_postgres_repo_error

Create the database, run migrations, and then run in IEX

{:ok, resource} = PostgresError.Resource.MapError |> Ash.Changeset.for_create(:create) |> Ash.create()
map = Application.get_env(:postgres_error, :map_bug)
# This will return the Jason Encoder error
resource |> Ash.Changeset.for_update(:bug_here, %{nested_map: map}) |> Ash.update()
# This will run as expected with no issue
resource |> Ash.Changeset.for_update(:update, %{nested_map: map}) |> Ash.update()

Expected behavior
I expected to be able to use my defined update actions to take nested maps and update accordingly.

** Runtime

  • Elixir version
  • Erlang version
  • OS
  • Ash version
  • any related extension versions

Additional context
Originally found here: https://elixirforum.com/t/getting-ash-postgres-error-for-map-type-attributes/65736

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions