sequelize: bug with recent v6.21.4 minified aliases in ORDER BY clause

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

v6.21.4 causes a bug (not present in v6.21.3) when generating the ORDER BY clause.

v6.21.3 is correct:

ORDER BY `order`.`ship_to_company` ASC, `order`.`ship_to_country` ASC, `order`.`ship_to_state` ASC, `order`.`ship_to_city` ASC, `order`.`ship_to_zip` ASC, `order`.`ship_to_address` ASC, `ServiceOrderLines`.`id` ASC;

v6.21.4 is incorrect:

ORDER BY `orderID``ship_to_company` ASC, `orderID``ship_to_country` ASC, `orderID``ship_to_state` ASC, `orderID``ship_to_city` ASC, `orderID``ship_to_zip` ASC, `orderID``ship_to_address` ASC, `ServiceOrderLines`.`id` ASC;

I have a table called orders, and when joining its alias becomes order:

LEFT OUTER JOIN `orders` AS `order` ON `ServiceOrderLines`.`order` = `order`.`id`

Reproducible Example

I will try to use SSCCE shortly, but I want to get this issue submitted, since I believe this is a trivial bugfix.

What do you expect to happen?

Produce valid SQL

What is actually happening?

Invalid ORDER BY clause is generated, and the code is re-writing order table alias as orderID for some reason.

Environment

  • Sequelize version: v6.21.4
  • Node.js version: v16.18.1
  • Database & Version: MySQL 8
  • Connector library & Version: mysql2@2.3.3

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

Yes, but I’d like to get your feedback first.

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

About this issue

  • Original URL
  • State: open
  • Created 2 years ago
  • Reactions: 1
  • Comments: 16 (8 by maintainers)

Most upvoted comments

Okay, then we’ll need to solve this in main first and then backport the fix to v6. Since there has been some work on issues related to this we should be fine if all current tests pass and the new test based on this issue. I do not think you need to worry about additional edge cases or really breaking things when looking into solving this

You did, thank you 😃

I have tried to replicate something that could produce this error bug couldn’t. I see you mentioned you were working on a SSCCE. Don’t hesitate to ping us when you have one so we can debug this further 😃