could not store strings into JSON field with mariadb 10.5
See original GitHub issueIssue Creation Checklist
- I understand that my issue will be automatically closed if I don’t fill in the requested information
- I have read the contribution guidelines
Bug Description
MariaDB consider JSON as String with some specific constraint / validity following SQL requirement. Since https://jira.mariadb.org/browse/MDEV-17832 (MariaDB 10.5.2) server send clearly data type as JSON. Driver can return resultset JSON value as JSON or String based on version.
The issue appears in case a JSON field contains a string: sequelize will try to JSON.parse
again failing with SyntaxError: Unexpected token e in JSON at position
(this does not happen when there is an object, an array, a boolean or an integer inside the JSON because of this check)
Reproducible Example
I’ve made a PR adding a unit test to explain the issue: https://github.com/sequelize/sequelize/pull/14800/commits/307fe9a692f4059fde85859198b6e51a97e64ae2#diff-828fc54d009f69d57b1371f55d990c3397dcbcad91b16fef724b9afe40932c71R199-R204
Here is the link to the SSCCE for this issue: https://github.com/sequelize/sequelize-sscce/pull/232
What do you expect to happen?
The same as mariadb 10.3 and the others backend
What is actually happening?
SyntaxError: Unexpected token e in JSON at position 1
at JSON.parse (<anonymous>)
at /home/les/dev/sequelize-sscce/node_modules/@sequelize/core/src/dialects/mariadb/query.js:208:46
at Array.map (<anonymous>)
at Query.handleJsonSelectQuery (/home/les/dev/sequelize-sscce/node_modules/@sequelize/core/src/dialects/mariadb/query.js:206:21)
at Query.formatResults (/home/les/dev/sequelize-sscce/node_modules/@sequelize/core/src/dialects/mariadb/query.js:139:12)
at Query.run (/home/les/dev/sequelize-sscce/node_modules/@sequelize/core/src/dialects/mariadb/query.js:80:17)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async /home/les/dev/sequelize-sscce/node_modules/@sequelize/core/src/sequelize.js:653:16
at async MySQLQueryInterface.select (/home/les/dev/sequelize-sscce/node_modules/@sequelize/core/src/dialects/abstract/query-interface.js:1014:12)
at async Function.findAll (/home/les/dev/sequelize-sscce/node_modules/@sequelize/core/src/model.js:1861:21)
Environment
- Sequelize version: 6.21.3 and 7.0.0-alpha.10
- Node.js version: v16.13.0
- If TypeScript related: TypeScript version:
- Database & Version: mariadb 10.5
- Connector library & Version: mariadb v3.0.1
Would you be willing to resolve this issue by submitting a Pull Request?
- Yes, I have the time and I know how to start (and finish) https://github.com/sequelize/sequelize/pull/14800.
- Yes, I have the time but I will need guidance.
- No, I don’t have the time, but my company or I are supporting Sequelize through donations on OpenCollective.
- No, I don’t have the time, and I understand that I will need to wait until someone from the community or maintainers is interested in resolving my issue.
Indicate your interest in the resolution of this issue by adding the 👍 reaction. Comments such as “+1” will be removed.
Issue Analytics
- State:
- Created a year ago
- Comments:7 (6 by maintainers)
Ah sorry, looks like we didn’t tag the PR correctly, this was actually solved by https://github.com/sequelize/sequelize/pull/15070. Thank you for offering to help nonetheless 😃
I’m removing the hacktoberfest label as it was completed by a maintainer