Failing test on delete_all if no where clause is specified
Hello!
Again, thanks for the great work!
Playing with this in a medium sized project I stumbled against a weird problem: when calling Repo.delete_all
with a query that is missing any other clause execpt the select
, this fails because the nil
in the {count, nil}
result is being enumerated.
Not knowing well the internals of Ecto/Repo I managed only to go this far for now and will retry tomorrow, but it may be simpler than I thought, so for the moment I cloned this repo and created a failing example test to reproduce it here
1) test Ecto.Adapter.Queryable#execute #delete_all from one table with select/only query, records (Ecto.Adapters.MnesiaQueryableIntegrationTest)
test/ecto/adapters/mnesia/queryable_test.exs:455
** (Protocol.UndefinedError) protocol Enumerable not implemented for nil of type Atom. This protocol is implemented for the following type(s): Qlc.Cursor, MapSet, Date.Range, GenEvent.Stream, Stream, File.Stream, IO.Stream, Map, HashSet, List, Range, HashDict, Function
code: case TestRepo.delete_all(from(s in TestSchema, select: s)) do
stacktrace:
(elixir) lib/enum.ex:1: Enumerable.impl_for!/1
(elixir) lib/enum.ex:141: Enumerable.reduce/3
(elixir) lib/enum.ex:3023: Enum.map/2
(ecto) lib/ecto/repo/queryable.ex:234: Ecto.Repo.Queryable.execute/4
test/ecto/adapters/mnesia/queryable_test.exs:469: (test)
note: editing mnesia.ex
's execute/5
in line 240 returning {length(result), []}
instead of {length(result), nil}
allows delete_all to return successfully, but ofc existing tests relying on nil
to be returned fail. From Ecto.Repo
delete_all/1
docs
It returns a tuple containing the number of entries and any returned result as second element. The second element is nil by default unless a select is supplied in the delete query.
so it is unclear to me if []
or nil
is the correct result, but you may have more information/sight than me!
Thanks again, let me know if I can add something or do something!