strapi / strapi

🚀 Strapi is the leading open-source headless CMS. It’s 100% JavaScript/TypeScript, fully customizable, and developer-first.
https://strapi.io
Other
63.42k stars 8.04k forks source link

Content History scheduled Job is using the wrong time format and wrong cron schedule format #21613

Closed derrickmehaffy closed 1 week ago

derrickmehaffy commented 1 week ago

Bug report

Required System information

Describe the bug

Every evening when the cron kicks off the user encounters the following error because the time format given to the database is incorrect:

/app/work/strapi/build_images/-snip-/node_modules/mysql2/lib/packets/packet.js:738
    const err = new Error(message);
                ^
Error: delete from `strapi_history_versions` where (`created_at` < '2024-07-07T21:00:00.024Z') - Incorrect datetime value: '2024-07-07T21:00:00.024Z' for column 'created_at' at row 1
    at Packet.asError (/app/work/strapi/build_images/-snip-/node_modules/mysql2/lib/packets/packet.js:738:17)
    at Query.execute (/app/work/strapi/build_images/-snip-/node_modules/mysql2/lib/commands/command.js:29:26)
    at Connection.handlePacket (/app/work/strapi/build_images/-snip-/node_modules/mysql2/lib/connection.js:481:34)
    at PacketParser.onPacket (/app/work/strapi/build_images/-snip-/node_modules/mysql2/lib/connection.js:97:12)
    at PacketParser.executeStart (/app/work/strapi/build_images/-snip-/node_modules/mysql2/lib/packet_parser.js:75:16)
    at Socket.<anonymous> (/app/work/strapi/build_images/-snip-/node_modules/mysql2/lib/connection.js:104:25)
    at Socket.emit (node:events:517:28)
    at Socket.emit (node:domain:489:12)
    at addChunk (node:internal/streams/readable:368:12)
    at readableAddChunk (node:internal/streams/readable:341:9) {
  code: 'ER_TRUNCATED_WRONG_VALUE',
  errno: 1292,
  sqlState: '22007',
  sqlMessage: "Incorrect datetime value: '2024-07-07T21:00:00.024Z' for column 'created_at' at row 1",
  sql: "delete from `strapi_history_versions` where (`created_at` < '2024-07-07T21:00:00.024Z')"
}
Node.js v18.20.2
error Command failed with exit code 1.

Steps to reproduce the behavior

  1. Enable enterprise mode
  2. Wait for cron to kick off
  3. See error

Expected behavior

Proper datetime format used

Screenshots

N/A

Code snippets

Appears to come from

https://github.com/strapi/strapi/blob/bbe5b7f1f46249a3154695d5ecc04fc4f74793b4/packages/core/content-manager/server/src/history/services/lifecycles.ts#L174-L189

Specifically this line:

https://github.com/strapi/strapi/blob/bbe5b7f1f46249a3154695d5ecc04fc4f74793b4/packages/core/content-manager/server/src/history/services/lifecycles.ts#L182

Additional context

Related TID: 8440

Also the syntax of this cron task is incorrect, it's using the older format and should be changed to the new format see: https://github.com/strapi/strapi/pull/21407

remidej commented 1 week ago

Regardless of the actual fix we should .catch that db query

derrickmehaffy commented 1 week ago

100% yeah a DB query like that shouldn't cause a complete app crash but should just be throwing a 500 error