duffelhq / paginator

Cursor-based pagination for Elixir Ecto
MIT License
750 stars 90 forks source link

Using total_count_limit raises an exception #164

Closed jgallinari closed 2 years ago

jgallinari commented 2 years ago

Hello, I found a little bug concerning the total_count_limit parameter.

This is what I have in my query params:

params: %{include_total_count: true, limit: 10, total_count_limit: "20"}

And this is what I get when running the query:

[error] #PID<0.802.0> running OssWeb.Endpoint (connection #PID<0.801.0>, stream id 1) terminated
Server: localhost:4013 (http)
Request: GET /v1/oem/test/subscriber?limit=10&include_total_count=true&total_count_limit=20
** (exit) an exception was raised:
    ** (ArithmeticError) bad argument in arithmetic expression
        (paginator 1.1.0) lib/paginator.ex:371: Paginator.total_count/4
        (paginator 1.1.0) lib/paginator.ex:181: Paginator.paginate/4

Looks like lib/paginator.ex:371, which is

      |> limit(^(total_count_limit + 1))

should be replaced with:

      |> limit(^total_count_limit + 1)

What do you think?

Regards, Jerome

jgallinari commented 2 years ago

Sorry, my mistake. I was using the wrong type for the parameter.