Skip to content

Nothing returns when used attributes with JSON field in table on MariaDB dialect #13027

Closed

Description

@hoanghog

What are you doing?

Here is the link with the problem https://github.com/roychri/sequelize_debug_2021-02-11

Trying to query a table with JSON type field with attribute projection, but if I don't state JSON field in attribute it will return nothing.

What do you expect to happen?

Wanted to retrieve data with attribute projection.

What is actually happening?

Returned nothing

Additional context

As described on git page I linked, if you remove the JSON field from model, it will works normally.

Environment

  • Sequelize version: 5.21.7 // Doesn't really matter
  • Node.js version: 14.4.0
  • Operating System: Windows

How does this problem relate to dialects?

  • 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

Would you be willing to resolve this issue by submitting a Pull Request?

  • Yes, I have the time and I know how to start.
  • Yes, I have the time but I don't know how to start, I would need guidance.
  • No, I don't have the time, although I believe I could do it if I had the time...
  • No, I don't have the time and I wouldn't even know how to start.

Activity

  1. alexjavier15 commented on Mar 24, 2021

    @alexjavier15

    I'm facing the same problem on mariadb. If I add a JSON field to the list of exluded attributes, the query returns nothing.

    I digged a bit. As far I can see, the results returned by mariadb query connection, always return null for the JSON attribute, even if its not part of the Select statement od the SQL query. Somehow this break the query handler (_groupJoinData function to be more specific. This is caused by the handleJsonSelectQuery.

    handleJsonSelectQuery(rows) {
    if (!this.model || !this.model.fieldRawAttributesMap) {
    return;
    }
    for (const _field of Object.keys(this.model.fieldRawAttributesMap)) {
    const modelField = this.model.fieldRawAttributesMap[_field];
    if (modelField.type instanceof DataTypes.JSON) {
    //value is return as String, no JSON
    rows = rows.map(row => {
    row[modelField.fieldName] = row[modelField.fieldName] ? JSON.parse(row[modelField.fieldName]) : null;
    if (DataTypes.JSON.parse) {
    return DataTypes.JSON.parse(modelField, this.sequelize.options, row[modelField.fieldName]);
    }
    return row;
    });
    }
    }
    }

    I changed the logic to skip setting null to the JSON attribute by default in my project and worked just fine.

    Check the workaround in #12583 (comment)

  2. added 3 commits that reference this issue on May 13, 2021
    bc0273c
    3ef69ba
    84c5da6
  3. github-actions commented on Oct 27, 2021

    @github-actions
    Contributor

    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. 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions