Contentful logo

Contentful Community

Intermittent bug when trying to paginate through entries from a content type

Context

Hey! I’m currently trying to make a search on my website that queries some entries of a specific content type on Contentful using pagination. I’m using the term “pancakes” to search for the entries and I use the [match] operator on a text field to find them. I made that query manually on Contentful’s dashboard first and I got 10 entries (9 are published and 1 is a draft).

This is the query I use on the getEntries method:

{
  content_type: <content type name>,
  resolveLinks: true,
  skip: req.query.skip || 0,
  limit: req.query.limit || 9,
  order: req.query.sort,
  select: [<a bunch of fields>]
  'fields.name[match]': req.query.search;
}

skip, limit, order and search field values are defined on the request query or use the default value.

So for the first request I send this query to my backend: ?skip=0&limit=9&search=pancakes
and I get:

{
  "total": 9,
  "skip": 0,
  "limit": 9,
}

Which is totally correct. But then when I try to get the next page with: ?skip=9&limit=9&search=pancakes

{
  "total": 452,
  "skip": 9,
  "limit": 9,
}

I get that as a result, 9 entries from a total of 452 that have nothing to do with what I’m searching (for context, I have a total of 478 entries of that content type, so it’s not even just bringing everything).

Since I have 9 published entries that match the query, I would expect to just receive this:

{
  "total": 0,
  "skip": 9,
  "limit": 9,
}

Expected Behavior

To send this request to my backend: ?skip=9&limit=9&search=pancakes and always get this as response:

{
  "total": 0,
  "skip": 9,
  "limit": 9,
}

Other relevant infos

This bug is only happening on my prod environment which uses outdated versions of node, npm and contenful.js itself. I tried to downgrade my local machine’s node version to match the one in the prod server, and I couldn’t reproduce the bug locally. So I believe this is not an issue related to the outdated versions.

Also, this bug is intermittent. Sometimes it gives me the expected response, but most of the time it gives me that bizarre response.

Environment

  • Language Version: Node v6.17.1
  • Package Manager Version: 3.10.10
  • Operating System: Linux 4.4.0-201-generic 233-Ubuntu SMP x86_64 x86_64 x86_64 GNU/Linux
  • Package Version: 5.1.3
  • Which API are you using?: Delivery

Any opinion on this?

Hey @mbernardes, could you submit a support ticket with the link to this post? We may need to impersonate your Contentful account and try to reproduce the problem