Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Query syntax error upon saving for content type with name: XXXs and plural XXXses #5141

Closed
dankostov opened this issue Jan 30, 2020 · 5 comments
Labels
issue: bug Issue reporting a bug severity: medium If it breaks the basic use of the product but can be worked around source: core:strapi Source is core/strapi package status: confirmed Confirmed by a Strapi Team member or multiple community members

Comments

@dankostov
Copy link

dankostov commented Jan 30, 2020

Describe the bug
When the content type name ends with 'XXXs' and the plural form is 'XXXses' upon saving of new entry i get this error:

select distinct `lotuses_components`.* from `lotuses_components` where `field` = 'translations' and `component_type` in ('components_lotuses_translations') and `lotuses_components`.`lotuse_id` in (6) order by `order` asc - ER_BAD_FIELD_ERROR: Unknown column 'lotuses_components.lotuse_id' in 'where clause'

The column in the table is properly named - lotuses_components.lotus_id not lotuses_components.lotuse_id

Stack trace:

error Error: ER_BAD_FIELD_ERROR: Unknown column 'XXXses_components.XXXse_id' in 'where clause'
    at Query.Sequence._packetToError (/home/userdir/strapi/my_project_v3_2/node_modules/mysql/lib/protocol/sequences/Sequence.js:47:14)
    at Query.ErrorPacket (/home/userdir/strapi/my_project_v3_2/node_modules/mysql/lib/protocol/sequences/Query.js:79:18)
    at Protocol._parsePacket (/home/userdir/strapi/my_project_v3_2/node_modules/mysql/lib/protocol/Protocol.js:291:23)
    at Parser._parsePacket (/home/userdir/strapi/my_project_v3_2/node_modules/mysql/lib/protocol/Parser.js:433:10)
    at Parser.write (/home/userdir/strapi/my_project_v3_2/node_modules/mysql/lib/protocol/Parser.js:43:10)
    at Protocol.write (/home/userdir/strapi/my_project_v3_2/node_modules/mysql/lib/protocol/Protocol.js:38:16)
    at Socket.<anonymous> (/home/userdir/strapi/my_project_v3_2/node_modules/mysql/lib/Connection.js:88:28)
    at Socket.<anonymous> (/home/userdir/strapi/my_project_v3_2/node_modules/mysql/lib/Connection.js:526:10)
    at Socket.emit (events.js:193:13)
    at addChunk (_stream_readable.js:295:12)
    at readableAddChunk (_stream_readable.js:276:11)
    at Socket.Readable.push (_stream_readable.js:231:10)
    at TCP.onStreamRead (internal/stream_base_commons.js:154:17)
    --------------------
    at Protocol._enqueue (/home/userdir/strapi/my_project_v3_2/node_modules/mysql/lib/protocol/Protocol.js:144:48)
    at Connection.query (/home/userdir/strapi/my_project_v3_2/node_modules/mysql/lib/Connection.js:198:25)
    at /home/userdir/strapi/my_project_v3_2/node_modules/knex/lib/dialects/mysql/index.js:130:18
    at Promise._execute (/home/userdir/strapi/my_project_v3_2/node_modules/bluebird/js/release/debuggability.js:384:9)
    at Promise._resolveFromExecutor (/home/userdir/strapi/my_project_v3_2/node_modules/bluebird/js/release/promise.js:518:18)
    at new Promise (/home/userdir/strapi/my_project_v3_2/node_modules/bluebird/js/release/promise.js:103:10)
    at Client_MySQL._query (/home/userdir/strapi/my_project_v3_2/node_modules/knex/lib/dialects/mysql/index.js:124:12)
    at Client_MySQL.query (/home/userdir/strapi/my_project_v3_2/node_modules/knex/lib/client.js:158:17)
    at /home/userdir/strapi/my_project_v3_2/node_modules/knex/lib/transaction.js:331:24
    at Promise._execute (/home/userdir/strapi/my_project_v3_2/node_modules/bluebird/js/release/debuggability.js:384:9)
    at Promise._resolveFromExecutor (/home/userdir/strapi/my_project_v3_2/node_modules/bluebird/js/release/promise.js:518:18)
    at new Promise (/home/userdir/strapi/my_project_v3_2/node_modules/bluebird/js/release/promise.js:103:10)
    at Client_MySQL.trxClient.query (/home/userdir/strapi/my_project_v3_2/node_modules/knex/lib/transaction.js:326:12)
    at Runner.query (/home/userdir/strapi/my_project_v3_2/node_modules/knex/lib/runner.js:135:36)
    at /home/userdir/strapi/my_project_v3_2/node_modules/knex/lib/runner.js:39:23
    at tryCatcher (/home/userdir/strapi/my_project_v3_2/node_modules/bluebird/js/release/util.js:16:23)

Steps to reproduce the behavior

  1. Create content type lotus, use defaults
  2. Create component license with text filed license
  3. Create component translations with fields: name - text, description rich text, add the license component as single use, make it required
  4. Add the translations component to lotus as repeatable use
  5. Go and create an entry
  6. See the error

I reproduced it with the following models:
lotus content type

{
  "connection": "default",
  "collectionName": "lotuses",
  "info": {
    "name": "lotus"
  },
  "options": {
    "increments": true,
    "timestamps": true
  },
  "attributes": {
    "name": {
      "type": "string"
    },
    "translations": {
      "type": "component",
      "repeatable": false,
      "component": "lotuses.translations"
    }
  }
}

license component

{
  "info": {
    "name": "license",
    "icon": "ad"
  },
  "options": {},
  "attributes": {
    "number": {
      "type": "string"
    }
  },
  "connection": "default",
  "collectionName": "components_common_licenses"
}

translations component

{
  "connection": "default",
  "collectionName": "components_lotuses_translations",
  "info": {
    "name": "translations",
    "icon": "adjust"
  },
  "options": {},
  "attributes": {
    "name": {
      "type": "string"
    },
    "description": {
      "type": "richtext",
      "required": true
    },
    "license": {
      "type": "component",
      "repeatable": false,
      "component": "common.license",
      "required": true
    }
  }
}

Expected behavior
The query should be properly generated based on the actual column name which is lotus_id.
And the entry should save without an issue.

System

  • Node.js version: v11.15.0
  • NPM version: 6.7.0
  • Strapi version: 3.0.0-beta.18.6
  • Database: Mysql
  • Operating system: Ubuntu
@lauriejim
Copy link
Contributor

Hello! I tried to reproduce your issue using your steps but I wasn't able to reproduce.
Can you please precise your steps if I messed something?
Here is what I did - https://www.loom.com/share/649b1b1ee8814ebea4f134dc70f14cc9

@dankostov dankostov changed the title Query syntax error upon saving for content type with name: XXXs and plural XXXses [Updated] Query syntax error upon saving for content type with name: XXXs and plural XXXses Feb 6, 2020
@dankostov
Copy link
Author

@lauriejim Hi, i have managed to reproduce it, outside of my app code, the issue's description is updated with more specific details. It seems that it's happening when you have 2 inherited components and a little bit longer content type name ending on "us" like "lotus" and "lotuses"
The model is like this: content type -> component (repeatable) -> component (single)

@lauriejim lauriejim changed the title [Updated] Query syntax error upon saving for content type with name: XXXs and plural XXXses Query syntax error upon saving for content type with name: XXXs and plural XXXses Feb 6, 2020
@lauriejim lauriejim added severity: medium If it breaks the basic use of the product but can be worked around status: confirmed Confirmed by a Strapi Team member or multiple community members issue: bug Issue reporting a bug and removed issue: help wanted labels Feb 6, 2020
@lauriejim
Copy link
Contributor

Great got it! thank you for reporting this issue!

@lauriejim lauriejim added the source: core:strapi Source is core/strapi package label Feb 11, 2020
@dankostov dankostov reopened this Feb 21, 2020
@dankostov
Copy link
Author

dankostov commented Mar 4, 2020

Hi @lauriejim , when do you think this will will be worked on?

@alexandrebodin
Copy link
Member

Hi, THis issues was fixed in release 3.0.0-beta.19.4. See this merged PR for implementation details ;) #5607

@strapi strapi locked as resolved and limited conversation to collaborators Apr 8, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
issue: bug Issue reporting a bug severity: medium If it breaks the basic use of the product but can be worked around source: core:strapi Source is core/strapi package status: confirmed Confirmed by a Strapi Team member or multiple community members
Projects
None yet
Development

No branches or pull requests

3 participants