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

Incorrect handling of pg table aliases in JOIN ON clauses when using non-default schema in 7.0.0-alpha.37 #17091

Open
3 of 6 tasks
chriswheeldon-peakon opened this issue Feb 15, 2024 · 1 comment

Comments

@chriswheeldon-peakon
Copy link

chriswheeldon-peakon commented Feb 15, 2024

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

This is essentially a duplicate of #15749 except pertaining to ON clauses rather than WHERE clauses.

I am using Sequelize and Postgres and setting a non-default schema (i.e. not public) when initialising Sequelize. When I make a find call with an include I am seeing that Sequelize is aliasing the FROM table (e.g. FROM "schema"."table" as "Alias") and is using that alias in the ON clause. However, it is producing an invalid statement by prefixing the alias with the schema (e.g. ON "schema"."Alias"."col" ...).

I can workaround the bug by removing the schema from the Sequelize constructor options and instead setting a schema when initialising each model. However, this has some drawbacks e.g. calls such as dropAllEnums use the constructor provided schema.

Reproducible Example

I have attempted to create a minimal, reproducible example at https://github.com/chriswheeldon-peakon/sequelize-v7-alias-bug/tree/510d766b06a0062b48d19e76e62134704a1a502d

What do you expect to happen?

Where the table alias is used in the on clause it should not be prefixed with the schema.

What is actually happening?

When using a non-default schema (i.e. not public) then sequelize is prefixing the alias with the schema when referring to it in the join on clause.

Environment

  • Sequelize version: @sequelize/core@7.0.0-alpha.37
  • Node.js version: v18.14.1
  • Database & Version: PostgreSQL 15.5
  • Connector library & Version: pg@8.10.0

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.

@chriswheeldon-peakon chriswheeldon-peakon added pending-approval Bug reports that have not been verified yet, or feature requests that have not been accepted yet type: bug labels Feb 15, 2024
@WikiRik
Copy link
Member

WikiRik commented Feb 15, 2024

Likely due to this, so if we fix the TODO this issue should also be fixed;

// TODO: use whereItemsQuery to generate the entire "ON" condition.
let joinOn = `${this.quoteTable(asLeft)}.${this.quoteIdentifier(columnNameLeft)}`;

@WikiRik WikiRik removed the pending-approval Bug reports that have not been verified yet, or feature requests that have not been accepted yet label Feb 15, 2024
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