Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/ecto/adapter/queryable.ex
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,14 @@ defmodule Ecto.Adapter.Queryable do
def prepare_query(operation, repo_name_or_pid, queryable, opts \\ []) do
%{adapter: adapter, cache: cache} = Ecto.Repo.Registry.lookup(repo_name_or_pid)

counter = Keyword.get(opts, :counter, 0)
query_cache? = Keyword.get(opts, :query_cache, true)

{_meta, prepared, _cast_params, dump_params} =
queryable
|> Ecto.Queryable.to_query()
|> Ecto.Query.Planner.ensure_select(operation == :all)
|> Ecto.Query.Planner.query(operation, cache, adapter, 0, query_cache?)
|> Ecto.Query.Planner.query(operation, cache, adapter, counter, query_cache?)

{prepared, dump_params}
end
Expand Down
2 changes: 1 addition & 1 deletion lib/ecto/query/planner.ex
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ defmodule Ecto.Query.Planner do
def query(query, operation, cache, adapter, counter, query_cache?) do
{query, params, key} = plan(query, operation, adapter)
{cast_params, dump_params} = Enum.unzip(params)
key = if query_cache?, do: key, else: :nocache
key = if query_cache?, do: {key, counter}, else: :nocache
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zachdaniel I thought it would be better to always add the counter, to reduce the number of branches, but it seems that either using a list is wrong or we are messing with the key in an incompatible way. Can you please take a deeper look?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry I'm not quite following.

it seems that either using a list is wrong or we are messing with the key in an incompatible way.

WDYM by using a list?

Is this about the test failures? The seem like timeouts in the GH actions to me but maybe I'm missing something.

Copy link
Copy Markdown
Member

@josevalim josevalim Apr 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not so sure. I have cloned ecto, pulled your branch, rebased master, and ECTO_PATH=../ecto ECTO_ADAPTER=pg mix test in ecto_sql fails for me.

And I decided to always return a tuple with the counter so we don't have hidden behaviour depending if counter is zero or not.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will do the same and investigate 👌

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@josevalim I could be missing something, but when I do the same I get all tests passing 🤔

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What did you run and which project? CI is also failing but it was not failing before my changes (and passed with yours).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry. I understand now. I didn't realize you had pushed to the branch 🤦‍♂️. The CI failures here seem like timeouts and my branch passed ecto_sql tests locally but I didn't pull. Will investigate 😄

query_with_cache(key, query, operation, cache, adapter, counter, cast_params, dump_params)
end

Expand Down
Loading