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

Postgrex.Result command field as a list #546

Closed
thiamsantos opened this issue May 28, 2021 · 2 comments
Closed

Postgrex.Result command field as a list #546

thiamsantos opened this issue May 28, 2021 · 2 comments

Comments

@thiamsantos
Copy link
Contributor

The documentation says sthat the field command of Postgrex.Result is a "An atom of the query command, for example: :select or :insert;". https://github.com/elixir-ecto/postgrex/blob/v0.15.9/lib/postgrex/result.ex#L5

However I'm getting a list in this field.

{:ok,
    %Postgrex.Result{
      columns: nil,
      command: [:rollback, :release],
      connection_id: 540,
      messages: [],
      num_rows: nil,
      rows: nil
    }}

I'm getting this behavior while listening to telemetry events from ecto. I'm using this sending this command field to an external metric system.

The behavior is correct and we should update the documentation accordlying?

@josevalim
Copy link
Member

Can you please provide an example of a query that is returning the above? The atom :release doesn't appear anywhere in this codebase and the codebase always asserts it is an atom, so I am thinking there is potentially something else at play here. Please include what is your Postgrex version too. Thanks.

@thiamsantos
Copy link
Contributor Author

I could isolate to the error to multi transaction rolling back. In the test that triggers the behavior, it is trying to update a existing record with a invalid reference id.

changeset = FinancialEntry.changeset(financial_entry, %{transaction_id: Ecto.UUID.generate()})

Ecto.Multi.new()
|> Ecto.Multi.update(:update, changeset)
|> MyApp.Repo.transaction()

These are the events that I'm getting in telemetry:

{[:my_app, :repo, :query],
 %{
   options: [],
   params: [],
   query: "begin",
   repo: MyApp.Repo,
   result: {:ok,
    %Postgrex.Result{
      columns: nil,
      command: :savepoint,
      connection_id: 1024,
      messages: [],
      num_rows: nil,
      rows: nil
    }},
   source: nil,
   type: :ecto_sql_query
 }}
{[:my_app, :repo, :query],
 %{
   options: [],
   params: [
     <<32, 17, 156, 70, 58, 248, 75, 124, 130, 100, 141, 148, 132, 121, 39, 71>>,
     ~U[2021-05-28 19:55:46.283853Z],
     <<86, 9, 85, 178, 225, 247, 74, 210, 150, 118, 129, 233, 8, 161, 27, 158>>
   ],
   query: "UPDATE \"financial_entries\" SET \"transaction_id\" = $1, \"updated_at\" = $2 WHERE \"id\" = $3",
   repo: MyApp.Repo,
   result: {:error,
    %Postgrex.Error{
      connection_id: 1024,
      message: nil,
      postgres: %{
        code: :foreign_key_violation,
        constraint: "financial_entries_transaction_id_fkey",
        detail: "Key (transaction_id)=(20119c46-3af8-4b7c-8264-8d9484792747) is not present in table \"transactions\".",
        file: "ri_triggers.c",
        line: "2772",
        message: "insert or update on table \"financial_entries\" violates foreign key constraint \"financial_entries_transaction_id_fkey\"",
        pg_code: "23503",
        routine: "ri_ReportViolation",
        schema: "public",
        severity: "ERROR",
        table: "financial_entries",
        unknown: "ERROR"
      },
      query: nil
    }},
   source: nil,
   type: :ecto_sql_query
 }}
{[:my_app, :repo, :query],
 %{
   options: [],
   params: [],
   query: "rollback",
   repo: MyApp.Repo,
   result: {:ok,
    %Postgrex.Result{
      columns: nil,
      command: [:rollback, :release],
      connection_id: 1024,
      messages: [],
      num_rows: nil,
      rows: nil
    }},
   source: nil,
   type: :ecto_sql_query
 }}
{[:my_app, :repo, :query],
 %{
   options: [],
   params: [],
   query: "rollback",
   repo: MyApp.Repo,
   result: {:ok,
    %Postgrex.Result{
      columns: nil,
      command: [:rollback, :release],
      connection_id: 1024,
      messages: [],
      num_rows: nil,
      rows: nil
    }},
   source: nil,
   type: :ecto_sql_query
 }}

Deps version:

* postgrex 0.15.9 (Hex package) (mix)
  locked at 0.15.9 (postgrex) 61071910
  ok
* ecto 3.6.1 (Hex package) (mix)
  locked at 3.6.1 (ecto) cbb3294a
  ok
* ecto_sql 3.6.1 (Hex package) (mix)
  locked at 3.6.1 (ecto_sql) 66f35c3f
  ok

Postgres version:

11.7

Elixir version:

Erlang/OTP 24 [erts-12.0.1] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] [jit]

Elixir 1.12.0 (compiled with Erlang/OTP 24)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants