question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

could not store strings into JSON field with mariadb 10.5

See original GitHub issue

Issue 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

and a fix https://github.com/sequelize/sequelize/pull/14800/commits/307fe9a692f4059fde85859198b6e51a97e64ae2#diff-e932ecd8820c194a793f77847ac06c9421f8bc2814db587fac9be1ceb839a116R188

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?


Indicate your interest in the resolution of this issue by adding the 👍 reaction. Comments such as “+1” will be removed.

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:7 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
ephyscommented, Oct 6, 2022

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 😃

0reactions
ephyscommented, Oct 7, 2022

I’m removing the hacktoberfest label as it was completed by a maintainer

Read more comments on GitHub >

github_iconTop Results From Across the Web

JSON Data Type - MariaDB Knowledge Base
The JSON type in MySQL stores the JSON object in a compact form, not as LONGTEXT as in MariaDB. This means that row...
Read more >
Sequelize crash - mariaDB 10.5.4 & JSON field · Issue #12583
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....
Read more >
MariaDB query columns into JSON - Stack Overflow
This can be very easily achieved by using JSON_OBJECTAGG function. Note that you need to have MariaDB version atleast 10.5.0 or above, ...
Read more >
Does MariaDB support native JSON column data type?
2 Answers 2 · 2. Till 10.2.6,not support native JSON yet. · 1. They store the json as a plain text only as...
Read more >
Working with Json fields (Concepts) - Prisma
The Json field supports a few additional types, such as string and boolean . ... You need to store data that does not...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found