-
Notifications
You must be signed in to change notification settings - Fork 1
fix: oban lifeline plugin errors #57
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
Closed
+68
−15
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -38,7 +38,49 @@ defmodule EctoLibSql.Query do | |
|
|
||
| def describe(query, _opts), do: query | ||
|
|
||
| def encode(_query, params, _opts), do: params | ||
| # Convert Elixir types to SQLite-compatible values before sending to NIF | ||
| def encode(_query, params, _opts) do | ||
| Enum.map(params, &encode_param/1) | ||
| end | ||
|
|
||
| defp encode_param(%DateTime{} = dt), do: DateTime.to_iso8601(dt) | ||
| defp encode_param(%NaiveDateTime{} = dt), do: NaiveDateTime.to_iso8601(dt) | ||
| defp encode_param(%Date{} = d), do: Date.to_iso8601(d) | ||
| defp encode_param(%Time{} = t), do: Time.to_iso8601(t) | ||
| defp encode_param(%Decimal{} = d), do: Decimal.to_string(d) | ||
| defp encode_param(value), do: value | ||
|
|
||
| # Normalize results for ecto_sql compatibility. | ||
| # Rules: | ||
| # 1. columns MUST ALWAYS be a list (even empty []), NEVER nil | ||
| # 2. rows should be nil only for write commands without RETURNING that affected rows | ||
| # 3. For all other cases (SELECT, RETURNING queries), rows must be a list | ||
| def decode(_query, result, _opts) when is_map(result) do | ||
| columns = case Map.get(result, :columns) do | ||
| nil -> [] | ||
| cols when is_list(cols) -> cols | ||
| _ -> [] | ||
| end | ||
|
|
||
| cmd = Map.get(result, :command) | ||
| rows = Map.get(result, :rows) | ||
| num_rows = Map.get(result, :num_rows, 0) | ||
|
|
||
| rows = cond do | ||
| # Write commands that affected rows but have no RETURNING -> rows should be nil | ||
| cmd in [:insert, :update, :delete] and rows == [] and num_rows > 0 and columns == [] -> | ||
| nil | ||
| # All other cases: rows must be a list | ||
| rows == nil -> | ||
| [] | ||
| true -> | ||
| rows | ||
| end | ||
|
|
||
| result | ||
| |> Map.put(:columns, columns) | ||
| |> Map.put(:rows, rows) | ||
| end | ||
|
Comment on lines
+53
to
+83
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Tighten
Proposed fix- # Normalize results for ecto_sql compatibility.
+ # Normalise results for ecto_sql compatibility.
# Rules:
# 1. columns MUST ALWAYS be a list (even empty []), NEVER nil
# 2. rows should be nil only for write commands without RETURNING that affected rows
# 3. For all other cases (SELECT, RETURNING queries), rows must be a list
def decode(_query, result, _opts) when is_map(result) do
columns = case Map.get(result, :columns) do
nil -> []
cols when is_list(cols) -> cols
_ -> []
end
cmd = Map.get(result, :command)
rows = Map.get(result, :rows)
num_rows = Map.get(result, :num_rows, 0)
rows = cond do
# Write commands that affected rows but have no RETURNING -> rows should be nil
cmd in [:insert, :update, :delete] and rows == [] and num_rows > 0 and columns == [] ->
nil
# All other cases: rows must be a list
- rows == nil ->
+ rows == nil ->
[]
+ not is_list(rows) ->
+ []
true ->
rows
end🤖 Prompt for AI Agents |
||
|
|
||
| def decode(_query, result, _opts), do: result | ||
| end | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: ocean/ecto_libsql
Length of output: 87
🏁 Script executed:
Repository: ocean/ecto_libsql
Length of output: 3588
🏁 Script executed:
Repository: ocean/ecto_libsql
Length of output: 448
🏁 Script executed:
Repository: ocean/ecto_libsql
Length of output: 43
🏁 Script executed:
Repository: ocean/ecto_libsql
Length of output: 1327
🏁 Script executed:
Repository: ocean/ecto_libsql
Length of output: 897
🏁 Script executed:
Repository: ocean/ecto_libsql
Length of output: 210
🏁 Script executed:
Repository: ocean/ecto_libsql
Length of output: 459
🏁 Script executed:
Repository: ocean/ecto_libsql
Length of output: 990
🏁 Script executed:
Repository: ocean/ecto_libsql
Length of output: 3323
🌐 Web query:
DBConnection.Query encode/3 callback signature params contract💡 Result:
Signature/contract:
Notes / common expectations:
Sources:
🌐 Web query:
Elixir DBConnection.Query protocol documentation encode💡 Result:
The DBConnection.Query protocol defines encode/3 as:
Reference documentation: DBConnection.Query (hexdocs). [1]
(DBConnection shows encode is invoked when preparing/executing and handles EncodeError by re-preparing.) [2]
Sources:
[1] DBConnection.Query — db_connection (protocol docs).
[2] DBConnection implementation showing encode usage and EncodeError handling (lib/db_connection.ex).
🏁 Script executed:
Repository: ocean/ecto_libsql
Length of output: 43
🏁 Script executed:
Repository: ocean/ecto_libsql
Length of output: 1395
🏁 Script executed:
# Check test files to see how encode is called head -100 test/ecto_adapter_test.exsRepository: ocean/ecto_libsql
Length of output: 3127
🏁 Script executed:
Repository: ocean/ecto_libsql
Length of output: 43
🏁 Script executed:
Repository: ocean/ecto_libsql
Length of output: 43
🏁 Script executed:
Repository: ocean/ecto_libsql
Length of output: 3014
🏁 Script executed:
Repository: ocean/ecto_libsql
Length of output: 6261
🏁 Script executed:
Repository: ocean/ecto_libsql
Length of output: 43
🏁 Script executed:
Repository: ocean/ecto_libsql
Length of output: 112
🏁 Script executed:
Repository: ocean/ecto_libsql
Length of output: 4534
🏁 Script executed:
Repository: ocean/ecto_libsql
Length of output: 43
🏁 Script executed:
Repository: ocean/ecto_libsql
Length of output: 2210
🏁 Script executed:
Repository: ocean/ecto_libsql
Length of output: 43
🏁 Script executed:
Repository: ocean/ecto_libsql
Length of output: 43
🏁 Script executed:
Repository: ocean/ecto_libsql
Length of output: 43
🌐 Web query:
DBConnection Elixir encode callback receives list params or generic?💡 Result:
Short answer: generic — the encode callback takes params() :: any(), not specifically a list. DBConnection passes whatever your adapter/query uses (lists, maps, tuples, etc.), and the DBConnection.Query.encode implementation for your adapter defines how they’re turned into iodata. [1][2]
🏁 Script executed:
Repository: ocean/ecto_libsql
Length of output: 112
🏁 Script executed:
Repository: ocean/ecto_libsql
Length of output: 224
Add guard to
encode/3to prevent crashes on non-list params.The DBConnection.Query protocol specifies
encode/3receivesparamsasany()type, not guaranteed to be a list.Enum.map/2will raise ifparamsisnilor a non-list, causing failures before the NIF layer. The codebase already usesis_list()guards elsewhere (e.g.,normalise_args_for_query/2), confirming this edge case was anticipated.Proposed fix
📝 Committable suggestion
🤖 Prompt for AI Agents