aesmail / kaffy

Powerfully simple admin package for phoenix applications
https://kaffy.fly.dev/admin/
MIT License
1.3k stars 153 forks source link

[BUG] Compilation error on Elixir 1.17 #312

Closed TheArrowsmith closed 1 month ago

TheArrowsmith commented 1 month ago

Versions Used Kaffy: 0.10.2 Phoenix: 1.7.11 Elixir: 1.17.0-rc.0

I'm getting a compilation error after upgrading to Elixir 1.17-rc.0. The only thing I changed is the Elixir version; everything worked fine on 1.16.

==> kaffy
Compiling 26 files (.ex)

== Compilation error in file lib/kaffy/resource_query.ex ==
** (Ecto.Query.CompileError) binding list should contain only variables or `{as, var}` tuples, got: ...
    (ecto 3.10.3) expanding macro: Ecto.Query.from/2
    (kaffy 0.10.2) lib/kaffy/resource_query.ex:188: Kaffy.ResourceQuery.build_query/7
    (elixir 1.17.0-rc.0) expanding macro: Kernel.if/2
    (kaffy 0.10.2) lib/kaffy/resource_query.ex:184: Kaffy.ResourceQuery.build_query/7
    (elixir 1.17.0-rc.0) expanding macro: Kernel.if/2

The error is coming from these lines in Kaffy, that pass ... to Ecto.Query.from

                if Kaffy.ResourceSchema.field_type(the_association, f) == :string or
                     term_type == :string do
                  term = "%#{term}%"

                  from([..., r] in current_query,
                    or_where: ilike(type(field(r, ^f), :string), ^term)
                  )
                else
                  if Kaffy.ResourceSchema.field_type(schema, f) in [:id, :integer] and
                       term_type == :decimal do
                    current_query
                  else
                    from([..., r] in current_query,
                      or_where: field(r, ^f) == ^term
                    )
                  end
                end

I'm not sure if this a problem with Kaffy per se or with Ecto, or with Elixir 1.17.0-rc.0. But I see the following in the Elixir changelog for 1.17.0-rc.0:

Resolve inconsistencies of how .. and ... are handled at the AST level

… which may be related.

Does anyone know what might be going wrong here and how it could be fixed?

TheArrowsmith commented 1 month ago

This turned out to be an issue with Ecto, which was fixed here: https://github.com/elixir-ecto/ecto/commit/aeff511c709bd6e07a8735da3928ac561910158a

Upgrading to Ecto 3.11.2 solved my issue.