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

camel case to snake case issue in destroy() method call for an instance #14256

Open
2 of 7 tasks
testmpi opened this issue Mar 16, 2022 · 2 comments
Open
2 of 7 tasks

Comments

@testmpi
Copy link

testmpi commented Mar 16, 2022

Issue Creation Checklist

[ X] I have read the contribution guidelines

Issue Description

I am using with postgresal dialact, sequelize version is 6.14.0 for nodejs

The model is defined with underscored: true

findOne() method correctly convert the field name from camel case to snake case and return the instance.

when I call destroy() of the instance, it execute query with camel case field which case the error.

on findOne() method call:

Executing (default): SELECT "token", "user_id" AS "userId", "token_type" AS "tokenType", "expires", "blocklisted", "organization_id" AS "organizationId", "created_at" AS "createdAt", "updated_at" AS "updatedAt" FROM "tokens" 
AS "token" WHERE "token"."token" = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOjEsImlhdCI6MTY0NzI3Njc5NiwiZXhwIjoxNjQ5ODY1MTk2LCJ0eXBlIjoicmVmcmVzaCJ9.AVaZzOjALodjIeSud4lpSHSyb76nLN6h8PixtIMx61M' AND "token"."blocklisted" 
= false AND "token"."token_type" = 'refresh';
token {
  dataValues: {
    token: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOjEsImlhdCI6MTY0NzI3Njc5NiwiZXhwIjoxNjQ5ODY1MTk2LCJ0eXBlIjoicmVmcmVzaCJ9.AVaZzOjALodjIeSud4lpSHSyb76nLN6h8PixtIMx61M',
    userId: 1,
    tokenType: 'refresh',
    expires: 2022-04-13T13:53:16.508Z,
    blocklisted: false,
    organizationId: 1,
    createdAt: 2022-03-14T15:53:16.509Z,
    updatedAt: 2022-03-14T15:53:16.509Z
  },
  _previousDataValues: {
    token: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOjEsImlhdCI6MTY0NzI3Njc5NiwiZXhwIjoxNjQ5ODY1MTk2LCJ0eXBlIjoicmVmcmVzaCJ9.AVaZzOjALodjIeSud4lpSHSyb76nLN6h8PixtIMx61M',
    userId: 1,
    tokenType: 'refresh',
    expires: 2022-04-13T13:53:16.508Z,
    blocklisted: false,
    organizationId: 1,
    createdAt: 2022-03-14T15:53:16.509Z,
    updatedAt: 2022-03-14T15:53:16.509Z
  },
  uniqno: 1,
  _changed: Set(0) {},
  _options: {
    isNewRecord: false,
    _schema: null,
    _schemaDelimiter: '',
    raw: true,
    attributes: [
      'token',
      'userId',
      'tokenType',
      'expires',
      'blocklisted',
      'organizationId',
      'createdAt',
      'updatedAt'
    ]
  },
  isNewRecord: false
}

on destroy() method call:

Executing (default): DELETE FROM "tokens" WHERE "token" = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOjEsImlhdCI6MTY0NzI3Njc5NiwiZXhwIjoxNjQ5ODY1MTk2LCJ0eXBlIjoicmVmcmVzaCJ9.AVaZzOjALodjIeSud4lpSHSyb76nLN6h8PixtIMx61M' AND "tokenType" = 'refresh' AND "blocklisted" = false
Error
    at Query.run (E:\workspace\p4w\p4wserver\node_modules\sequelize\lib\dialects\postgres\query.js:50:25)
    at E:\workspace\p4w\p4wserver\node_modules\sequelize\lib\sequelize.js:313:28
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async PostgresQueryInterface.delete (E:\workspace\p4w\p4wserver\node_modules\sequelize\lib\dialects\abstract\query-interface.js:382:12)
    at async model.destroy (E:\workspace\p4w\p4wserver\node_modules\sequelize\lib\model.js:2542:16)
    at async Object.logout (E:\workspace\p4w\p4wserver\services\auth.service.js:34:3)
    at async E:\workspace\p4w\p4wserver\controllers\auth.controller.js:19:3 {
  name: 'SequelizeDatabaseError',
  parent: error: column "tokenType" does not exist
      at Parser.parseErrorMessage (E:\workspace\p4w\p4wserver\node_modules\pg-protocol\dist\parser.js:287:98)
      at Parser.handlePacket (E:\workspace\p4w\p4wserver\node_modules\pg-protocol\dist\parser.js:126:29)
      at Parser.parse (E:\workspace\p4w\p4wserver\node_modules\pg-protocol\dist\parser.js:39:38)
      at Socket.<anonymous> (E:\workspace\p4w\p4wserver\node_modules\pg-protocol\dist\index.js:11:42)
      at Socket.emit (node:events:390:28)
      at addChunk (node:internal/streams/readable:315:12)
      at readableAddChunk (node:internal/streams/readable:289:9)
      at Socket.Readable.push (node:internal/streams/readable:228:10)
      at TCP.onStreamRead (node:internal/stream_base_commons:199:23) {
    length: 237,
    severity: 'ERROR',
    code: '42703',
    detail: undefined,
    hint: 'Perhaps you meant to reference the column "tokens.token_type".',
    position: '206',
    internalPosition: undefined,
    internalQuery: undefined,
    where: undefined,
    schema: undefined,
    table: undefined,
    column: undefined,
    dataType: undefined,
    constraint: undefined,
    file: 'd:\\pginstaller_13.auto\\postgres.windows-x64\\src\\backend\\parser\\parse_relation.c',
    line: '3513',
    routine: 'errorMissingColumn',
    sql: `DELETE FROM "tokens" WHERE "token" = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOjEsImlhdCI6MTY0NzI3Njc5NiwiZXhwIjoxNjQ5ODY1MTk2LCJ0eXBlIjoicmVmcmVzaCJ9.AVaZzOjALodjIeSud4lpSHSyb76nLN6h8PixtIMx61M' AND "tokenType" = 'refresh' AND "blocklisted" = false`,
    parameters: undefined
  },
  original: error: column "tokenType" does not exist
      at Parser.parseErrorMessage (E:\workspace\p4w\p4wserver\node_modules\pg-protocol\dist\parser.js:287:98)
      at Parser.handlePacket (E:\workspace\p4w\p4wserver\node_modules\pg-protocol\dist\parser.js:126:29)
      at Parser.parse (E:\workspace\p4w\p4wserver\node_modules\pg-protocol\dist\parser.js:39:38)
      at Socket.<anonymous> (E:\workspace\p4w\p4wserver\node_modules\pg-protocol\dist\index.js:11:42)
      at Socket.emit (node:events:390:28)
      at addChunk (node:internal/streams/readable:315:12)
      at readableAddChunk (node:internal/streams/readable:289:9)
      at Socket.Readable.push (node:internal/streams/readable:228:10)
      at TCP.onStreamRead (node:internal/stream_base_commons:199:23) {
    length: 237,
    severity: 'ERROR',
    code: '42703',
    detail: undefined,
    **hint: 'Perhaps you meant to reference the column "tokens.token_type".',**
    position: '206',
    internalPosition: undefined,
    internalQuery: undefined,
    where: undefined,
    schema: undefined,
    table: undefined,
    column: undefined,
    dataType: undefined,
    constraint: undefined,
    file: 'd:\\pginstaller_13.auto\\postgres.windows-x64\\src\\backend\\parser\\parse_relation.c',
    line: '3513',
    routine: 'errorMissingColumn',
    sql: `DELETE FROM "tokens" WHERE "token" = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOjEsImlhdCI6MTY0NzI3Njc5NiwiZXhwIjoxNjQ5ODY1MTk2LCJ0eXBlIjoicmVmcmVzaCJ9.AVaZzOjALodjIeSud4lpSHSyb76nLN6h8PixtIMx61M' AND "tokenType" = 'refresh' AND "blocklisted" = false`,
    parameters: undefined
  },
  sql: `DELETE FROM "tokens" WHERE "token" = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOjEsImlhdCI6MTY0NzI3Njc5NiwiZXhwIjoxNjQ5ODY1MTk2LCJ0eXBlIjoicmVmcmVzaCJ9.AVaZzOjALodjIeSud4lpSHSyb76nLN6h8PixtIMx61M' AND "tokenType" 
= 'refresh' AND "blocklisted" = false`,
  parameters: {}
}

Kindly help me in fixing this issue.

Additional context

Add any other context or screenshots about the issue here.

Issue Template Checklist

Is this issue dialect-specific?

  • No. This issue is relevant to Sequelize as a whole.
  • Yes. This issue only applies to the following dialect(s): XXX, YYY, ZZZ
  • I don't know.

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.
@ephys
Copy link
Member

ephys commented Mar 16, 2022

Hello,

Please use Code Blocks to make your issue readable: https://docs.github.com/en/get-started/writing-on-github/working-with-advanced-formatting/creating-and-highlighting-code-blocks

Your issue may be the same as #11112

@testmpi
Copy link
Author

testmpi commented Mar 16, 2022

Hi @ephys ,

As you said, I updated with code block.

Yes, As you mentioned, it is same issue as mentioned in #11112

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

No branches or pull requests

2 participants