You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Sequelize crash - mariaDB 10.5.4 & JSON field #12583
I think this problem happens regardless of the dialect.
I think this problem happens only for the following dialect(s): mariadb
I don't know, I was using PUT-YOUR-DIALECT-HERE, with connector library version XXX and database version XXX
EDIT:
After debugging, i noticed that row[modelField.fieldName] is already an object, so obviously, if sequelize tries to json.parse an object it throws this error.... please fix this bug.
Reacted by Milad, Michael, Aliaksei Lebedzeu, Oleg Taranov and Vaibhav Pandey
server error SyntaxError: Unexpected token o in JSON at position 1
at JSON.parse (<anonymous>)
at /node_modules/sequelize/lib/dialects/mariadb/query.js:183:72
at Array.map (<anonymous>)
at Query.handleJsonSelectQuery (/node_modules/sequelize/lib/dialects/mariadb/query.js:182:21)
at Query.formatResults (/node_modules/sequelize/lib/dialects/mariadb/query.js:127:12)
at Query.run (/node_modules/sequelize/lib/dialects/mariadb/query.js:72:17)
at processTicksAndRejections (internal/process/task_queues.js:93:5)
at async /node_modules/sequelize/lib/sequelize.js:619:16
at async MySQLQueryInterface.select (/node_modules/sequelize/lib/dialects/abstract/query-interface.js:938:12)
at async Function.findAll (/node_modules/sequelize/lib/model.js:1753:21) {
Looked into this a bit after encountering the same issue. It seems like this is coming from the mariadb connector itself. With 10.4, it returns the data as a string (thus Sequelize needs to parse it), whereas it's parsing the result with server 10.5.
This test case would suggest that this behavior is intentional, though seemingly undocumented. It also shows a temporary workaround (which is also undocumented from what I can tell): we can pass autoJsonMap: false as a dialect option.
Found a work around. This function mentioned above can be corrected (I replaced the .prototype in the top level of my project). Only JSON.parse if object is a string.
if(modelField.typeinstanceofDataTypes.JSON){//value is return as String, no JSONrows=rows.map(row=>{if(row[modelField.fieldName]&&(typeofrow[modelField.fieldName]==='string')){//don't see much point of setting to null as JSON.parse throws exception if it doesn't workrow[modelField.fieldName]=JSON.parse(row[modelField.fieldName]);}if(DataTypes.JSON.parse){returnDataTypes.JSON.parse(modelField,this.sequelize.options,row[modelField.fieldName]);}returnrow;});}
Reacted by alexjavier15, firstfu, Jonathan Duclos and Rick Bergfalk
Looked into this a bit after encountering the same issue. It seems like this is coming from the mariadb connector itself. With 10.4, it returns the data as a string (thus Sequelize needs to parse it), whereas it's parsing the result with server 10.5.
This test case would suggest that this behavior is intentional, though seemingly undocumented. It also shows a temporary workaround (which is also undocumented from what I can tell): we can pass autoJsonMap: false as a dialect option.
If this is still open I tried the fixes above those did not work for me.
const result = await logs.findAll({
where: {
[Op.and]: [{ Rank: { [Op.lte]: req.user.Rank } }, { ...where }],
},
offset: skipRecords,
limit: perPage,
order: [["ID", "DESC"]], //Works properly without this line
});
As soon as I add this order line I get error.
SyntaxError: Unexpected token o in JSON at position 1
at JSON.parse (<anonymous>)
at D:\Development\Projects\NodeJS\Chashma-Seed-Portal-API\node_modules\sequelize\lib\dialects\mariadb\query.js:186:72
at Array.map (<anonymous>)
at Query.handleJsonSelectQuery (D:\Development\Projects\NodeJS\Chashma-Seed-Portal-API\node_modules\sequelize\lib\dialects\mariadb\query.js:185:21)
at Query.formatResults (D:\Development\Projects\NodeJS\Chashma-Seed-Portal-API\node_modules\sequelize\lib\dialects\mariadb\query.js:130:12)
at Query.run (D:\Development\Projects\NodeJS\Chashma-Seed-Portal-API\node_modules\sequelize\lib\dialects\mariadb\query.js:74:17)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async D:\Development\Projects\NodeJS\Chashma-Seed-Portal-API\node_modules\sequelize\lib\sequelize.js:619:16
at async MySQLQueryInterface.select (D:\Development\Projects\NodeJS\Chashma-Seed-Portal-API\node_modules\sequelize\lib\dialects\abstract\query-interface.js:953:12)
at async Function.findAll (D:\Development\Projects\NodeJS\Chashma-Seed-Portal-API\node_modules\sequelize\lib\model.js:1753:21)
at async D:\Development\Projects\NodeJS\Chashma-Seed-Portal-API\routes\api\logs.js:35:24
GET /api/logs 500 173.942 ms - 35
Query generated by the above code is
SELECT `ID`, `Date`, `User`, `Details`, `Rank`, `Changes` FROM `logs` AS `logs` WHERE (`logs`.`Rank` <= 3 AND (`logs`.`ID` LIKE '%%' OR `logs`.`Date` LIKE 'Invalid date' OR `logs`.`User` LIKE '%%' OR `logs`.`Details` LIKE '%%' OR `logs`.`Rank` LIKE '%%' OR `logs`.`Changes` LIKE '\"%%\"')) ORDER BY `logs`.`ID` DESC LIMIT 0, 10
This issue has been automatically marked as stale because it has been open for 7 days without activity. It will be closed if no further activity occurs. If this is still an issue, just leave a comment or remove the "stale" label. 🙂
Activity
miladmeidanshahi commentedon Aug 9, 2020
same error
seally1186 commentedon Aug 13, 2020
Looked into this a bit after encountering the same issue. It seems like this is coming from the
mariadbconnector itself. With 10.4, it returns the data as a string (thus Sequelize needs to parse it), whereas it's parsing the result with server 10.5.This test case would suggest that this behavior is intentional, though seemingly undocumented. It also shows a temporary workaround (which is also undocumented from what I can tell): we can pass
autoJsonMap: falseas a dialect option.miladmeidanshahi commentedon Sep 12, 2020
@seally1186 doesn't worked 🤔
ciknowles commentedon Oct 16, 2020
Found a work around. This function mentioned above can be corrected (I replaced the .prototype in the top level of my project). Only JSON.parse if object is a string.
https://github.com/sequelize/sequelize/blob/master/src/dialects/mariadb/query.js#L180-L185
usb248 commentedon Nov 7, 2020
Solution : Encode your column to : utf8mb4_unicode_ci (was in utf8mb4_bin). Worked for me
remoreichsoellner commentedon Apr 10, 2021
Thanks! Works for me on Maria DB Server 10.5.9 Homebrew Mac (Local Install), hopefully also working on production Server.
Process JSON fields only if actually requested - fixes sequelize#13027 …
fix(mariadb): Process JSON fields only if actually requested (sequeli…
fix(mariadb): Process JSON fields only if actually requested (sequeli…
Arose-Niazi commentedon Aug 3, 2021
If this is still open I tried the fixes above those did not work for me.
As soon as I add this order line I get error.
Query generated by the above code is
Which is perfect
github-actions commentedon Oct 31, 2021
This issue has been automatically marked as stale because it has been open for 7 days without activity. It will be closed if no further activity occurs. If this is still an issue, just leave a comment or remove the "stale" label. 🙂
Arose-Niazi commentedon Oct 31, 2021
Leaving a comment to remove it from stale
github-actions commentedon Nov 18, 2021
🎉 This issue has been resolved in version 6.10.0 🎉
The release is available on:
Your semantic-release bot 📦🚀