Sometimes the query returns the wrong result

Problem

When running the following queries multiple times in a row within Kintone to get records, the result at times differ.

  • 種別 in ("新規") and HC名 = "QG" and 作業中 >= LAST_MONTH() and 作業完了 = "" and キャンセル有無 = "0" and 作業中 <= THIS_MONTH(LAST) order by レコード番号 desc limit 500 offset 0
  • 種別 in ("リピーター") and HC名 = "QG" and 作業完了 >= LAST_MONTH() order by レコード番号 desc limit 500 offset 0
  • 種別 in ("リピーター") and HC名 = "QG" and 見積依頼 >= LAST_MONTH() order by レコード番号 desc limit 500 offset 0
  • 種別 in ("リピーター") and HC名 = "QG" and 作業中 >= LAST_MONTH() and 作業完了 = "" and キャンセル有無 = "0" and 作業中 <= THIS_MONTH(LAST) order by レコード番号 desc limit 500 offset 0
  • 種別 in ("新規") and HC名 = "QG" and 作業完了 = LAST_YEAR() order by レコード番号 desc limit 500 offset 0
  • 種別 in ("新規") and HC名 = "QG" and 見積依頼 = LAST_YEAR() order by レコード番号 desc limit 500 offset 0
  • 種別 in ("リピーター") and HC名 = "QG" and 作業完了 = LAST_YEAR() order by レコード番号 desc limit 500 offset 0
  • 種別 in ("リピーター") and HC名 = "QG" and 見積依頼 = LAST_YEAR() order by レコード番号 desc limit 500 offset 0

Reproduce the bug

Please follow the following steps to reproduce this bug:

  1. Paste the following JS code in the console of this page.
  2. Try to run test() method then press enter key many times.

You will see that for some time, Kintone return the incorrect total count and caused user’s bug.

Like the attached picture:

async function test() {
  let queryList = [
    '種別 in ("新規") and HC名 = "QG" and 作業中 >= LAST_MONTH() and 作業完了 = "" and キャンセル有無 = "0" and 作業中 <= THIS_MONTH(LAST) order by レコード番号 desc limit 500 offset 0',
    '種別 in ("リピーター") and HC名 = "QG" and 作業完了 >= LAST_MONTH() order by レコード番号 desc limit 500 offset 0',
    '種別 in ("リピーター") and HC名 = "QG" and 見積依頼 >= LAST_MONTH() order by レコード番号 desc limit 500 offset 0',
    '種別 in ("リピーター") and HC名 = "QG" and 作業中 >= LAST_MONTH() and 作業完了 = "" and キャンセル有無 = "0" and 作業中 <= THIS_MONTH(LAST) order by レコード番号 desc limit 500 offset 0',
    '種別 in ("新規") and HC名 = "QG" and 作業完了 = LAST_YEAR() order by レコード番号 desc limit 500 offset 0',
    '種別 in ("新規") and HC名 = "QG" and 見積依頼 = LAST_YEAR() order by レコード番号 desc limit 500 offset 0',
    '種別 in ("リピーター") and HC名 = "QG" and 作業完了 = LAST_YEAR() order by レコード番号 desc limit 500 offset 0',
    '種別 in ("リピーター") and HC名 = "QG" and 見積依頼 = LAST_YEAR() order by レコード番号 desc limit 500 offset 0',
  ];

  let tasks = queryList.map(r => {
    return query(r);
  });

  let result = [];
  let sum = 0;
  for (let i = 0; i < tasks.length; i++) {
    let r = await tasks[i];
    result.push(r);
    sum += parseInt(r.toString());
  }
  console.log(sum);
  console.log(result);
}

async function query(query) {
  return new Promise((resolve, reject) => {
    const body = {
      'app': 5679,
      'query': query,
      'fields': ['HC支店名', 'HC支店番号', '見積依頼'],
      totalCount: true
    };

    kintone.api(kintone.api.url('/k/v1/records', true), 'GET', body, function (resp) {
      // success
      resolve(resp.totalCount);
    }, function (error) {
      // error
      console.log(error);
    });
  });
}

Hello @user1 ,

Welcome to the Kintone Developer Forum & thank you for posting your question!
Include your code and the screenshot of the console are also very helpful!

The only thing that is missing for us to reproduce your bug is the Kintone App’s setup.

Please list out the fields (field types and field codes) that the query refers to.
Given that the query uses the Japanese field codes, this becomes even more important.

Thank you for your time,
Genji

Hello @Genji ,

I am sorry, I cannot share specifically how the Kintone App is set up.

However, here is some additional information we found in our bug investigation that we can share:

Kintone App Specs

The Kintone App that sometimes returns the incorrect query bug is complex.

  • The main App has 136 fields and 490,000 records

  • The main App also has Lookup fields that are pulling data from a secondary App. The secondary App has 290,000 records.

Query Bug Details

  • This query bug does not occur consistently. We see it happen at random times. This bug is hard to reproduce.

  • The bug most often occurs during Japanese working hours: 9:00 ~ 18:00 JST

Hope it helps.

Hello @user1 ,

Thank you for the additional information.

Not being able to recreate the bug limit our ability to help you here on the Developer Forum.

However, it seems that the query bug is likely caused by the main App and the secondary App going beyond the recommended limits specified in the List of Limit Values | Kintone Documentation Site document.

Relevant Limits

Number of Records

We recommend limiting Kintone Apps to 50,000 records.

Apps with more records will perform slower. Perhaps the API calls with the query are not getting the specified records within the API Timeout Limits
successfully?

API for manipulating app records

  • The maximum number of records that can be retrieved at once: 500
  • The maximum number of records that can be added, updated, or deleted at once: 100

Using the Bulk Request API, you can manipulate up to 2,000 records (100 records x 20 requests = 2,000 records) at once.

Recommendation

Breaking up the big Apps

We suggest that you avoid using Apps with over 50,000 records.
Perhaps breaking the large App into smaller Apps based on type, year, etc.

Contacting Kintone’s Sales Engineers

If you wish to investigate this bug more in-depth, please contact support. Our Sales Engineers would then be able to run tests on your Subdomain and the Apps you mentioned to determine exactly the cause of the query bug.

Request an App’s record limits increase

Finally, you can also contact support to increase the App’s record limits.