fuelen / ecto_dev_logger

An alternative logger for Ecto queries
Apache License 2.0
147 stars 14 forks source link

Error with ts_vector type and %Postgrex.Lexeme{} #19

Closed mrdotb closed 1 year ago

mrdotb commented 1 year ago

Hello thanks for the lib !

I noticed this bug while working with text search in postgres.

The minimal steps to reproduce with iex

sql = "SELECT ts_rank_cd($1, websearch_to_tsquery($2), 4)"
opts = [
  [
    %Postgrex.Lexeme{word: "cadr", positions: [{5, :A}]},
    %Postgrex.Lexeme{word: "colon", positions: [{4, :B}]},
    %Postgrex.Lexeme{word: "grygkar", positions: [{2, :B}]},
    %Postgrex.Lexeme{word: "hugo", positions: [{1, :B}]},
    %Postgrex.Lexeme{word: "margot", positions: [{3, :B}]},
    %Postgrex.Lexeme{word: "noir", positions: [{6, :A}]}
  ],
  "hugo"
]
Repo.query(sql, opts)

[error] Handler [:ecto_dev_logger, :ttr, :repo] has failed and has been detached. Class=:error
Reason=%Protocol.UndefinedError{
  protocol: Ecto.DevLogger.PrintableParameter,
  value: %Postgrex.Lexeme{word: "cadr", positions: [{5, :A}]},
  description: ""
}
Stacktrace=[
  {Ecto.DevLogger.PrintableParameter, :impl_for!, 1,
   [file: 'lib/ecto/dev_logger/printable_parameter.ex', line: 1]},
  {Ecto.DevLogger.PrintableParameter, :to_string_literal, 1,
   [file: 'lib/ecto/dev_logger/printable_parameter.ex', line: 37]},
  {Ecto.DevLogger.Utils, :"-all_to_string_literal/1-fun-0-", 2,
   [file: 'lib/ecto/dev_logger/printable_parameter.ex', line: 49]},
  {Enumerable.List, :reduce, 3, [file: 'lib/enum.ex', line: 4751]},
  {Enum, :reduce_while, 3, [file: 'lib/enum.ex', line: 2514]},
  {Ecto.DevLogger.Utils, :all_to_string_literal, 1,
   [file: 'lib/ecto/dev_logger/printable_parameter.ex', line: 48]},
  {Ecto.DevLogger.PrintableParameter.List, :to_string_literal, 1,
   [file: 'lib/ecto/dev_logger/printable_parameter.ex', line: 225]},
  {Ecto.DevLogger.PrintableParameter.List, :to_expression, 1,
   [file: 'lib/ecto/dev_logger/printable_parameter.ex', line: 214]},
  {Ecto.DevLogger, :"-inline_params/4-fun-1-", 3,
   [file: 'lib/ecto/dev_logger.ex', line: 121]},
  {Regex, :apply_list, 5, [file: 'lib/regex.ex', line: 756]},
  {Regex, :apply_list, 5, [file: 'lib/regex.ex', line: 751]},
  {Regex, :replace, 4, [file: 'lib/regex.ex', line: 686]},
  {Ecto.DevLogger, :"-telemetry_handler/4-fun-0-", 6,
   [file: 'lib/ecto/dev_logger.ex', line: 94]},
  {Logger, :__do_log__, 4, [file: 'lib/logger.ex', line: 884]},
  {:telemetry, :"-execute/3-fun-0-", 4,
   [
     file: '/home/john/Projects/websites/tontontresors/ttr/deps/telemetry/src/telemetry.erl',
     line: 160
   ]},
  {:lists, :foreach_1, 2, [file: 'lists.erl', line: 1442]},
  {Ecto.Adapters.SQL, :log, 4, [file: 'lib/ecto/adapters/sql.ex', line: 1079]},
  {DBConnection, :log, 5, [file: 'lib/db_connection.ex', line: 1559]},
  {Postgrex, :query_prepare_execute, 4, [file: 'lib/postgrex.ex', line: 361]},
  {:elixir, :"-eval_external_handler/1-fun-2-", 4,
   [file: 'src/elixir.erl', line: 309]}
]

{:ok,
 %Postgrex.Result{
   command: :select,
   columns: ["ts_rank_cd"],
   rows: [[0.4000000059604645]],
   num_rows: 1,
   connection_id: 534,
   messages: []
 }}
fuelen commented 1 year ago

Hi @mrdotb

I've pushed a commit https://github.com/fuelen/ecto_dev_logger/commit/8f30a6dba38651b2bfc5122d8851a621bf518a63 to main. Could you test it please?

mrdotb commented 1 year ago

It's working. Thank you !

fuelen commented 1 year ago

@mrdotb released v0.9.0 :tada: