Ash Postgres id column error on update

I’ve got an app with multitenency and I’m trying to do a basic update on on resource via GraphQL using the default update action and I’m getting this error:

POST /gql
“superhotel.hotellite.local”
[debug] Processing with Absinthe.Plug
Parameters: %{“operationName” => “UpdateLodgingItem”, “query” => “mutation UpdateLodgingItem($updateLodgingItemId: ID!, $input: UpdateLodgingItemInput) {\n updateLodgingItem(id: $updateLodgingItemId, input: $input) {\n errors {\n code\n fields\n message\n shortMessage\n vars\n }\n result {\n checkInDate\n checkOutDate\n id\n name\n quantity\n rate\n subtotal\n tax\n taxRate\n total\n }\n }\n}”, “variables” => %{“input” => %{“checkInDate” => “2024-05-31”, “checkOutDate” => “2024-06-01”, “name” => “”, “paymentId” => “c252365d-b5c0-4b28-ad17-ccfb70b3d102”, “rate” => “100.0”, “taxRate” => “0.067”}, “updateLodgingItemId” => “0405f3b0-fe49-433d-8b7f-cc7c10b889bb”}}
Pipelines: [:graphql]
“Set tenant to superhotel”
[debug] ABSINTHE schema=App.GraphqlSchema variables=%{“input” => %{“checkInDate” => “2024-05-31”, “checkOutDate” => “2024-06-01”, “name” => “”, “paymentId” => “c252365d-b5c0-4b28-ad17-ccfb70b3d102”, “rate” => “100.0”, “taxRate” => “0.067”}, “updateLodgingItemId” => “0405f3b0-fe49-433d-8b7f-cc7c10b889bb”}

mutation UpdateLodgingItem($updateLodgingItemId: ID!, $input: UpdateLodgingItemInput) {
updateLodgingItem(id: $updateLodgingItemId, input: $input) {
errors {
code
fields
message
shortMessage
vars
}
result {
checkInDate
checkOutDate
id
name
quantity
rate
subtotal
tax
taxRate
total
}
}
}

[debug] QUERY ERROR source=“lodging_items” db=0.0ms queue=2.3ms idle=81.0ms
UPDATE “superhotel”.“lodging_items” AS l0 SET “payment_id” = s1.“payment_id”, “check_out_date” = s1.“check_out_date”, “check_in_date” = s1.“check_in_date”, “rate” = s1.“rate”, “tax_rate” = s1.“tax_rate”, “name” = s1.“name” FROM (SELECT $1::uuid AS “payment_id”, $2::date AS “check_out_date”, $3::date AS “check_in_date”, $4::decimal AS “rate”, $5::decimal AS “tax_rate”, $6::text AS “name” FROM “superhotel”.“lodging_items” AS sl0 WHERE (sl0.“id”::uuid = $7::uuid) LIMIT $8) AS s1 WHERE (l0.“id” = s1.“id”) RETURNING l0.“id”, l0.“name”, l0.“rate”, l0.“check_in_date”, l0.“check_out_date”, l0.“tax_rate”, l0.“payment_id” [“c252365d-b5c0-4b28-ad17-ccfb70b3d102”, ~D[2024-06-01], ~D[2024-05-31], Decimal.new(“100.0”), Decimal.new(“0.067”), nil, “0405f3b0-fe49-433d-8b7f-cc7c10b889bb”, 1]
↳ AshPostgres.DataLayer.update_query/4, at: lib/data_layer.ex:1411
[error] a85087ec-5abb-42a7-86d2-df0f5485f23d: Exception raised while resolving query.

** (Postgrex.Error) ERROR 42703 (undefined_column) column s1.id does not exist

query: UPDATE "superhotel"."lodging_items" AS l0 SET "payment_id" = s1."payment_id", "check_out_date" = s1."check_out_date", "check_in_date" = s1."check_in_date", "rate" = s1."rate", "tax_rate" = s1."tax_rate", "name" = s1."name" FROM (SELECT $1::uuid AS "payment_id", $2::date AS "check_out_date", $3::date AS "check_in_date", $4::decimal AS "rate", $5::decimal AS "tax_rate", $6::text AS "name" FROM "superhotel"."lodging_items" AS sl0 WHERE (sl0."id"::uuid = $7::uuid) LIMIT $8) AS s1 WHERE (l0."id" = s1."id") RETURNING l0."id", l0."name", l0."rate", l0."check_in_date", l0."check_out_date", l0."tax_rate", l0."payment_id"

hint: Perhaps you meant to reference the column "l0.id".

(ecto_sql 3.11.2) lib/ecto/adapters/sql.ex:1054: Ecto.Adapters.SQL.raise_sql_call_error/1
(ecto_sql 3.11.2) lib/ecto/adapters/sql.ex:952: Ecto.Adapters.SQL.execute/6
(ecto 3.11.2) lib/ecto/repo/queryable.ex:232: Ecto.Repo.Queryable.execute/4
(ash_postgres 2.0.6) lib/data_layer.ex:1411: AshPostgres.DataLayer.update_query/4
(ash 3.0.8) lib/ash/actions/update/bulk.ex:442: Ash.Actions.Update.Bulk.do_atomic_update/5
(ash 3.0.8) lib/ash/actions/update/bulk.ex:231: Ash.Actions.Update.Bulk.run/6
(ash_graphql 1.0.1) lib/graphql/resolver.ex:1224: AshGraphql.Graphql.Resolver.mutate/2
(absinthe 1.7.6) lib/absinthe/phase/document/execution/resolution.ex:234: Absinthe.Phase.Document.Execution.Resolution.reduce_resolution/1
(absinthe 1.7.6) lib/absinthe/phase/document/execution/resolution.ex:189: Absinthe.Phase.Document.Execution.Resolution.do_resolve_field/3
(absinthe 1.7.6) lib/absinthe/phase/document/execution/resolution.ex:174: Absinthe.Phase.Document.Execution.Resolution.do_resolve_fields/6
(absinthe 1.7.6) lib/absinthe/phase/document/execution/resolution.ex:145: Absinthe.Phase.Document.Execution.Resolution.resolve_fields/4
(absinthe 1.7.6) lib/absinthe/phase/document/execution/resolution.ex:88: Absinthe.Phase.Document.Execution.Resolution.walk_result/5
(absinthe 1.7.6) lib/absinthe/phase/document/execution/resolution.ex:67: Absinthe.Phase.Document.Execution.Resolution.perform_resolution/3
(absinthe 1.7.6) lib/absinthe/phase/document/execution/resolution.ex:24: Absinthe.Phase.Document.Execution.Resolution.resolve_current/3
(absinthe 1.7.6) lib/absinthe/pipeline.ex:408: Absinthe.Pipeline.run_phase/3
(absinthe_plug 1.5.8) lib/absinthe/plug.ex:536: Absinthe.Plug.run_query/4
(absinthe_plug 1.5.8) lib/absinthe/plug.ex:290: Absinthe.Plug.call/2
(phoenix 1.7.12) lib/phoenix/router/route.ex:42: Phoenix.Router.Route.call/2
(phoenix 1.7.12) lib/phoenix/router.ex:484: Phoenix.Router.__call__/5
(app 0.1.0) lib/app_web/endpoint.ex:1: AppWeb.Endpoint.plug_builder_call/2

Can you ensure that you’re fully updated on both ash and ash_postgres?

Pretty sure I am, but I’ll double check

I did a mix clean and mix deps.clean --all for good measure

:cry: okay in that case please open an issue in ash_postgres and I will look into it as soon as I am able :+1:

1 Like

I’ll dig a little more and try to repro on a basic app as well

I just tested destroy and it works, so I’m guessing it’s only in the update code, still digging…

Should be fixed in latest ash_postgres main, thanks :slight_smile:

1 Like

@zachdaniel Confirmed it’s fixed on that sample project, but my project with multitenancy is still broken, I think that the schema isn’t being used?

[warning] 5ea8e95d-2ec4-4731-afd3-8eb07ece735d: AshGraphql.Error not implemented for error:

** (Ash.Error.Unknown) Unknown Error

  • ** (Postgrex.Error) ERROR 42P01 (undefined_table) relation “lodging_items” does not exist
    query: SELECT l0."id", ((l0."rate"::decimal * (((l0."check_out_date"::date - l0."check_in_date"::date)))::decimal)::decimal + ((l0."rate"::decimal * (((l0."check_out_date"::date - l0."check_in_date"::date)))::decimal)::decimal * l0."tax_rate"::decimal)::decimal)::decimal::decimal, (((l0."check_out_date"::date - l0."check_in_date"::date)))::decimal::decimal, (l0."rate"::decimal * (((l0."check_out_date"::date - l0."check_in_date"::date)))::decimal)::decimal::decimal, ((l0."rate"::decimal * (((l0."check_out_date"::date - l0."check_in_date"::date)))::decimal)::decimal * l0."tax_rate"::decimal)::decimal::decimal FROM "lodging_items" AS l0 WHERE (l0."id"::uuid = $1::uuid)
  (ecto_sql 3.11.2) lib/ecto/adapters/sql.ex:1054: Ecto.Adapters.SQL.raise_sql_call_error/1
  (ecto_sql 3.11.2) lib/ecto/adapters/sql.ex:952: Ecto.Adapters.SQL.execute/6
  (ecto 3.11.2) lib/ecto/repo/queryable.ex:232: Ecto.Repo.Queryable.execute/4
  (ecto 3.11.2) lib/ecto/repo/queryable.ex:19: Ecto.Repo.Queryable.all/3
  (ash_postgres 2.0.6) lib/data_layer.ex:750: anonymous fn/3 in AshPostgres.DataLayer.run_query/2
  (ash_postgres 2.0.6) lib/data_layer.ex:748: AshPostgres.DataLayer.run_query/2
  (ash 3.0.9) lib/ash/actions/read/read.ex:2422: Ash.Actions.Read.run_query/4
  (ash 3.0.9) lib/ash/actions/read/read.ex:958: Ash.Actions.Read.reselect_and_load/5
  (ash 3.0.9) lib/ash/actions/read/read.ex:237: Ash.Actions.Read.do_run/3
  (ash 3.0.9) lib/ash/actions/read/read.ex:66: anonymous fn/3 in Ash.Actions.Read.run/3
  (ash 3.0.9) lib/ash/actions/read/read.ex:65: Ash.Actions.Read.run/3
  (ash 3.0.9) lib/ash.ex:1713: Ash.load/3
  (ash 3.0.9) lib/ash/actions/update/bulk.ex:2229: Ash.Actions.Update.Bulk.load_data/5
  (ash 3.0.9) lib/ash/actions/update/bulk.ex:482: Ash.Actions.Update.Bulk.do_atomic_update/5
  (ash 3.0.9) lib/ash/actions/update/bulk.ex:231: Ash.Actions.Update.Bulk.run/6
  (ash_graphql 1.1.1) lib/graphql/resolver.ex:1236: AshGraphql.Graphql.Resolver.mutate/2
  (absinthe 1.7.6) lib/absinthe/phase/document/execution/resolution.ex:234: Absinthe.Phase.Document.Execution.Resolution.reduce_resolution/1
  (absinthe 1.7.6) lib/absinthe/phase/document/execution/resolution.ex:189: Absinthe.Phase.Document.Execution.Resolution.do_resolve_field/3
  (absinthe 1.7.6) lib/absinthe/phase/document/execution/resolution.ex:174: Absinthe.Phase.Document.Execution.Resolution.do_resolve_fields/6
  (absinthe 1.7.6) lib/absinthe/phase/document/execution/resolution.ex:145: Absinthe.Phase.Document.Execution.Resolution.resolve_fields/4
    (elixir 1.16.1) lib/process.ex:860: Process.info/2
    (ash 3.0.9) lib/ash/error/unknown.ex:3: Ash.Error.Unknown."exception (overridable 2)"/1
    (ash 3.0.9) /Users/bryan/one-dashboard/one-dashboard/deps/splode/lib/splode.ex:211: Ash.Error.to_class/2
    (ash 3.0.9) lib/ash/error/error.ex:66: Ash.Error.to_error_class/2
    (ash 3.0.9) lib/ash/actions/read/read.ex:317: Ash.Actions.Read.do_run/3
    (ash 3.0.9) lib/ash/actions/read/read.ex:66: anonymous fn/3 in Ash.Actions.Read.run/3
    (ash 3.0.9) lib/ash/actions/read/read.ex:65: Ash.Actions.Read.run/3
    (ash 3.0.9) lib/ash.ex:1713: Ash.load/3
    (ash 3.0.9) lib/ash/actions/update/bulk.ex:2229: Ash.Actions.Update.Bulk.load_data/5
    (ash 3.0.9) lib/ash/actions/update/bulk.ex:482: Ash.Actions.Update.Bulk.do_atomic_update/5
    (ash 3.0.9) lib/ash/actions/update/bulk.ex:231: Ash.Actions.Update.Bulk.run/6
    (ash_graphql 1.1.1) lib/graphql/resolver.ex:1236: AshGraphql.Graphql.Resolver.mutate/2
    (absinthe 1.7.6) lib/absinthe/phase/document/execution/resolution.ex:234: Absinthe.Phase.Document.Execution.Resolution.reduce_resolution/1
    (absinthe 1.7.6) lib/absinthe/phase/document/execution/resolution.ex:189: Absinthe.Phase.Document.Execution.Resolution.do_resolve_field/3
    (absinthe 1.7.6) lib/absinthe/phase/document/execution/resolution.ex:174: Absinthe.Phase.Document.Execution.Resolution.do_resolve_fields/6
    (absinthe 1.7.6) lib/absinthe/phase/document/execution/resolution.ex:145: Absinthe.Phase.Document.Execution.Resolution.resolve_fields/4
    (absinthe 1.7.6) lib/absinthe/phase/document/execution/resolution.ex:88: Absinthe.Phase.Document.Execution.Resolution.walk_result/5
    (absinthe 1.7.6) lib/absinthe/phase/document/execution/resolution.ex:67: Absinthe.Phase.Document.Execution.Resolution.perform_resolution/3
    (absinthe 1.7.6) lib/absinthe/phase/document/execution/resolution.ex:24: Absinthe.Phase.Document.Execution.Resolution.resolve_current/3
    (absinthe 1.7.6) lib/absinthe/pipeline.ex:408: Absinthe.Pipeline.run_phase/3

The table name is lodging_items but with the schema added on it should be superhotel.lodging_items

I’ll create a repro example from that basic one and open another issue.

Hrm, the sample project didn’t reproduce, could be a bug on my end