Aggregate "COUNT" problem in query

V5.2.2 - Nodejs - Postgresql

After updating to the latest version, I’m getting this error:

  "status": "500",
  "message": "Cannot read properties of undefined (reading 'toJSON')",
  "stack": "TypeError: Cannot read properties of undefined (reading 'toJSON')\n    at formatRecord (/opt/node_app/lib/core/app.js:346:40)\n    at /opt/node_app/lib/core/app.js:367:45\n    at (<anonymous>)\n    at Object.options.postProcessResponse (/opt/node_app/lib/core/app.js:367:31)\n    at Client_PG.postProcessResponse (/opt/node_app/node_modules/knex/lib/client.js:162:26)\n    at /opt/node_app/node_modules/knex/lib/execution/runner.js:142:51\n    at runMicrotasks (<anonymous>)\n    at processTicksAndRejections (node:internal/process/task_queues:96:5)\n    at async Runner.ensureConnection (/opt/node_app/node_modules/knex/lib/execution/runner.js:272:14)\n    at async (/opt/node_app/node_modules/knex/lib/execution/runner.js:30:19)"

It happens with the “COUNT” field:

It was working fine until the latest update, I didn’t touch/change anything related to this

After reverting back to version 5.2.0 it works again, so it seems that an update in 5.2.1 or 5.2.2 is causing the issue

count is a bad choice of alias whatever the situation

So is date. Both have special meaning in SQL - always choose non reserved words for aliases where possible.

E.g. sale_count or sale_date

1 Like

I changed the aliases, but it didn’t solve the problem.

I was counting it with the date field, which was working before, but now it doesn’t.
It’s probably because of the updates regarding the datetime fields in the recent updates.

Changing the count aggregate to another property (company id in my case) solved the problem.

Are you sure it is the count field that is causing the error and not the date field? In the last update we updated how date fields are handled and that shouldn’t affect the count aggregate. Could you perhaps post the json of the action file.

Hi Patrick,

As I mentioned here:

The date time field with count doesn’t work. In my case it’s solved now by counting another field.

Do you still want me to post the json of the action file when using the datetime field as count option?

Hi @patrick
I don’t think this is where an aggregate is used but when the query includes something that produces a date output. I have a server action that has stopped working all of a sudden, producing the same error in dev tools.

It draws a list of users and includes a DoB field (set as DATE not DATETIME), when that is included in the query, it produces the error @htatd shows above

In my case, it seems some invalid dates 0000-00-00 have crept in and adjusting those fixed the issue. I’m going to go back and check my form validations but maybe there’s a way of handling these exceptions?

The 0000-00-00 is an invalid date, the parser doesn’t like that. I’ve update the code so that it will return a null value. (5.1 KB) unzip to lib/core.

1 Like

Just changed one back to an invalid date to test and it seems to work perfectly. Thanks @patrick

Fixed in Wappler 5.2.3

This topic was automatically closed after 2 days. New replies are no longer allowed.