[String can't be coerced into Integer] when i call lastest.json API

When i call lastest.json?page=0&per_page=10&foo=bar

     # TypeError:
     #   String can't be coerced into Integer
     #   ./lib/topic_query.rb:729:in `*'

https://github.dev/discourse/discourse/blob/0832cad803bb429a49595eab822a7c77dfa2088b/lib/topic_query.rb#L732-L737
I think can resolve by:

if options[:page]
  offset = options[:page].to_i * options[:per_page].to_i
  result = result.offset(offset) if offset > 0
end

This is a bit of a feature request, per_page is not part of our API (not used by the client at all). This would not fully solve the issue cause per_page would need to come with an upper limit of say maximum of 100-200.

Is there a specific reason you are looking to override page sizes?

2 Likes

Yes, We have a customer page to get the topics with waterfall flow.
Sure I think this is a feature request.
We can use default per_page and remove the per_page query.

1 Like