Cannot atomically update because Ash.Geometry does not support atomic updates

Hello everyone,

I’m having an issue with Ash.Geometry where I’m unable to update just the location. Here’s my code for reference:

New type to Geometry

defmodule JoinsApi.Types.Point4326 do
  use AshGeo.Geometry,
    storage_type: :"geometry(Point,4326)",
    geo_types: :point
end

Resource

update :update_location do
      argument :location, :geo_any do
        allow_nil? false
        constraints geo_types: :point
      end

      require_atomic? false

      change set_attribute(:location, arg(:location))
    end

Config Json Api Domain

json_api do
    routes do
      base_route "/profiles", JoinsApi.Accounts.Profile do
        get :read
        index :read
        post :create
        patch :update
        delete :destroy
        patch :update_location, route: "/:id/update_location"
      end

      base_route "/blocks", JoinsApi.Accounts.Block do
        get :read
        index :read
        post :create
        delete :destroy
      end
    end
  end

Even put required_automic? false, still show error:

{
	"errors": [
		{
			"code": "invalid",
			"id": "1dc2e6c6-2ec1-4ae4-ae7c-1caf7b3f78d8",
			"meta": {},
			"status": "400",
			"title": "Invalid",
			"detail": "Cannot atomically update JoinsApi.Accounts.Profile.location: Type `JoinsApi.Types.Point4326` does not support atomic updates"
		}
	],
	"jsonapi": {
		"version": "1.0"
	}
}

Payload I’m sending:

{
	"data": {
		"type": "profile",
		"attributes": {
			"location": {
				"coordinates": [
					55,
					44
				],
				"type": "Point"
			}
		}
	}
}

Hello :slight_smile: Please adjust your code formatting so that it is more readable. Specifically by using triple backticks. For example:

``` # <- triple backticks
your code here
``` # <- triple backticks

I’m not sure why what you’ve described would be happening.

Does it need to be an argument? Or can you use

accept [:location]

in this case?

I’m fairly new to using Ash, and I’m trying to update the location attribute. However, I’m not sure why, when I pass the path to the route, I receive the following error:

Even use a accept

update :update_location do
      accept [:location]
      argument :location, :geo_any do
        allow_nil? false
        constraints geo_types: :point
      end

      require_atomic? false

      change set_attribute(:location, arg(:location))
    end

If i remove argument, I’m getting error:

{
			"code": "invalid_attribute",
			"id": "ee12d0a5-bc9f-4e88-b67e-3a6d10a281d3",
			"meta": {},
			"status": "400",
			"title": "InvalidAttribute",
			"source": {
				"pointer": "/data/attributes/location"
			},
			"detail": "is invalid"
		}

When I try update location using de action:

{
	"errors": [
		{
			"code": "invalid",
			"id": "a12fec35-87cc-4de4-adfc-47fef443006a",
			"meta": {},
			"status": "400",
			"title": "Invalid",
			"detail": "Cannot atomically update JoinsApi.Accounts.Profile.location: Type `JoinsApi.Types.Point4326` does not support atomic updates"
		}
	],
	"jsonapi": {
		"version": "1.0"
	}
}

What I meant was to use accept instead of the argument.

update :update_location do
  accept [:location]
  # require_atomic? false <- shouldn't need this but maybe
end

Actually if remove argument I getting error that the value is invalid ;/.

Even if I leave require_atomic? I’m still getting:

Cannot atomically update JoinsApi.Accounts.Profile.location: Type `JoinsApi.Types.Point4326` does not support atomic updates

What version of ash and ash_postgres are you on? You’ll want to see what your locked version is not the version in your mix.exs is. You can run
mix hex.info ash and mix hex.info ash_postgres to see your locked versions.

If you haven’t, its a good idea to update to the latest version to see if we’ve already fixed your issue.

Actually I’m using the last version ;/

mix hex.info ash
A declarative, extensible framework for building Elixir applications.

Config: {:ash, "~> 3.4"}
Locked version: 3.4.18
Releases: 3.4.18, 3.4.17, 3.4.16, 3.4.15, 3.4.14, 3.4.13, 3.4.12, 3.4.11, ...

Licenses: MIT
Links:
  Discord: https://discord.gg/HTHRaaVPUc
  Forum: https://elixirforum.com/c/elixir-framework-forums/ash-framework-forum
  GitHub: https://github.com/ash-project/ash
  Website: https://ash-hq.org
mix hex.info ash_postgres
The PostgreSQL data layer for Ash Framework

Config: {:ash_postgres, "~> 2.4"}
Locked version: 2.4.1
Releases: 2.4.1, 2.4.0, 2.3.1, 2.3.0, 2.2.5, 2.2.4, 2.2.3, 2.2.2, ...

Licenses: MIT
Links:
  GitHub: https://github.com/ash-project/ash_postgres

What is the stack trace of the error?

Can you create a reproduction project for me? I will be able to debug much quicker that way.

You can easily create a new ash project with

mix igniter.new reproduction --install ash,ash_postgres

I’ve created a project to reproduction, thank you for the help

Project:

About stack trace error:
I can’t update the location at all but if I assign require_atomic? false I can only update via iex.

Error:

** (Ash.Error.Invalid) Invalid Error

* Cannot atomically update JoinsApi.Accounts.Profile.location: Type `JoinsApi.Types.Point4326` does not support atomic updates
  (elixir 1.17.2) lib/process.ex:864: Process.info/2
  (ash 3.4.18) lib/ash/error/changes/invalid_changes.ex:4: Ash.Error.Changes.InvalidChanges.exception/1
  (ash 3.4.18) lib/ash/changeset/changeset.ex:5627: Ash.Changeset.add_error/3
  (stdlib 6.0.1) maps.erl:860: :maps.fold_1/4
  (ash 3.4.18) lib/ash/changeset/changeset.ex:915: Ash.Changeset.run_atomic_change/3
  (ash 3.4.18) lib/ash/changeset/changeset.ex:760: anonymous fn/3 in Ash.Changeset.atomic_changes/2
  (elixir 1.17.2) lib/enum.ex:4858: Enumerable.List.reduce/3
  (elixir 1.17.2) lib/enum.ex:2585: Enum.reduce_while/3
  (ash 3.4.18) lib/ash/changeset/changeset.ex:758: Ash.Changeset.atomic_changes/2
  (ash 3.4.18) lib/ash/changeset/changeset.ex:641: Ash.Changeset.fully_atomic_changeset/4
  (ash 3.4.18) lib/ash/actions/update/update.ex:87: Ash.Actions.Update.run/4
  (ash 3.4.18) lib/ash.ex:2643: Ash.update/3
  (ash 3.4.18) lib/ash.ex:2583: Ash.update!/3
  (elixir 1.17.2) src/elixir.erl:386: :elixir.eval_external_handler/3
  (stdlib 6.0.1) erl_eval.erl:904: :erl_eval.do_apply/7
  (elixir 1.17.2) src/elixir.erl:364: :elixir.eval_forms/4
  (elixir 1.17.2) lib/module/parallel_checker.ex:112: Module.ParallelChecker.verify/1
  (iex 1.17.2) lib/iex/evaluator.ex:332: IEx.Evaluator.eval_and_inspect/3
  (iex 1.17.2) lib/iex/evaluator.ex:306: IEx.Evaluator.eval_and_inspect_parsed/3
  (iex 1.17.2) lib/iex/evaluator.ex:295: IEx.Evaluator.parse_eval_inspect/4
    (elixir 1.17.2) lib/process.ex:864: Process.info/2
    (ash 3.4.18) lib/ash/error/invalid.ex:3: Ash.Error.Invalid.exception/1
    (ash 3.4.18) /Users/kovi/Documents/tests/joins/joins_api/deps/splode/lib/splode.ex:211: Ash.Error.to_class/2
    (ash 3.4.18) lib/ash/error/error.ex:66: Ash.Error.to_error_class/2
    (ash 3.4.18) lib/ash/actions/update/bulk.ex:176: Ash.Actions.Update.Bulk.run/6
    (ash 3.4.18) lib/ash/actions/update/update.ex:157: Ash.Actions.Update.run/4
    (ash 3.4.18) lib/ash.ex:2643: Ash.update/3
    (ash 3.4.18) lib/ash.ex:2583: Ash.update!/3
    iex:6: (file)

Thank you for the reproduction :smiley: This should be fixed in the latest main branch of Ash, and will be in the next release.

You can try it out with {:ash, github: "ash-project/ash"}. Additionally, I’ve made a PR to ash_geo (not my project) to address the fact that the type does not support atomic updates.

1 Like

Oh that’s amazing, thank you so much o/.
It’ve worked!!

1 Like