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

Weird Failure When Using this.reload(); "Cannot use offset or limit without a model or order being set" #17321

Closed
3 of 6 tasks
klondikemarlen opened this issue May 9, 2024 · 2 comments
Labels
pending-approval Bug reports that have not been verified yet, or feature requests that have not been accepted yet type: bug

Comments

@klondikemarlen
Copy link

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

I'm doing a reload call after an increment call.

async getSlugAndIncrement(): Promise<string> {
  const originalSlug = this.slug

  await this.increment("nextIdentifier")
  await this.reload()

  return originalSlug
}

Reproducible Example

I haven't been able to duplicated this in the SSCCE repo, but by stepping through the source code, I can find where the behaviour starts to get weird.

My debugger shows that in line

const results = await this.queryInterface.select(this, this.table, selectOptions);

this.table is a model table definition, not a table name as expected by this.queryInterface.select

In the line above https://github.com/sequelize/sequelize/blob/ab663f53be4dc5b085ab815e2c84f68bddfef0a9/packages/core/src/model.js#L1425C5-L1425C70.
tableNames: Object.keys(tableNames) produces tableNames: [ '[object Object]' ]. The string literal, not the name of the table.

Because

tableNames[this.table] = true;

this.table is a model table definition not a table name.
this.table.tableName produces the table name as expected.

What do you expect to happen?

I expect the reload operation to succeed, without requiring me to pass the order like

await this.reload({ order: [['id', 'ASC']] })

What is actually happening?

Somewhere down the line, this.queryGenerator.selectQuery fails the isModelStatic check and errors.

Environment

  • Sequelize version: ^7.0.0-alpha.40
  • Node.js version: 20.10.0-alpine3.19
  • If TypeScript related: TypeScript version: ^5.4.5
  • Database & Version: mcr.microsoft.com/mssql/server:2022-latest
  • Connector library & Version: "@sequelize/mssql": "^7.0.0-alpha.40",

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 will need guidance.
  • No, I don't have the time, but my company or I are supporting Sequelize through donations on OpenCollective.
  • No, I don't have the time, and I understand that I will need to wait until someone from the community or maintainers is interested in resolving my issue.

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

@klondikemarlen klondikemarlen added pending-approval Bug reports that have not been verified yet, or feature requests that have not been accepted yet type: bug labels May 9, 2024
@klondikemarlen
Copy link
Author

@ephys Tagging you as an active developer, since this seems like something that might cause a bunch of weird errors that are hard to find. Apologies if I should not have tagged you.

@klondikemarlen
Copy link
Author

After more investigation this appears to be a problem with the build process in Jest + TS-Jest; I've fixed it by switching to Vitest, and explicitly setting the model and table name.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pending-approval Bug reports that have not been verified yet, or feature requests that have not been accepted yet type: bug
Projects
None yet
Development

No branches or pull requests

1 participant