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

v5: fix(postgres): parse enums correctly when describing a table #12411

Merged

Conversation

closingin
Copy link
Contributor

This PR is a cherry-pick of #12409, as the bug exists in v5 and v6!

Pull Request check-list

Please make sure to review and check all of these items:

  • Does npm run test or npm run test-DIALECT pass with this change (including linting)?
  • Does the description below contain a link to an existing issue (Closes #[issue]) or a description of the issue you are solving?
  • Have you added new tests to prevent regressions?
  • Is a documentation update included (if this change modifies existing APIs, or introduces new ones)?
  • Did you update the typescript typings accordingly (if applicable)?
  • Did you follow the commit message conventions explained in CONTRIBUTING.md?

Description of change

When you have a PostgreSQL table containing a user-defined enum, if the last value of this enum contains multiple words, using a describeTable() on it will generate an array with a trailing quote due to a bad parsing of the result data. It works well in other cases (as long as the enum doesn't end with a multi-word value).

Consider this schema:

CREATE TYPE my_enum AS ENUM ('foo', 'bar', 'foo bar');
CREATE TABLE my_table (
  foo my_enum
);

Sequelize uses array_agg(pg_catalog.pg_enum.enumlabel) to fetch the enum values, before passing it to QueryGenerator.fromArray() to parse it. In this case it will send the string {foo,bar,"foo bar"}, and the resulting array will be ['foo', 'bar', 'foo bar"'], with the unwanted trailing quote.


Tests aren't passing but I'm not sure that it's related to my fix, tell me if I need to change something! Here's the stacktrace just in case:

> mocha --require scripts/mocha-bootload --globals setImmediate,clearImmediate --exit --check-leaks --colors -t 30000 --reporter spec "test/integration/**/*.test.js"

FIXME: I want to be supported in this dialect as well :-(


  [POSTGRES] Alias
    1) "before each" hook for "should uppercase the first letter in alias getter, but not in eager loading"


  0 passing (1m)
  1 failing

  1) "before each" hook for "should uppercase the first letter in alias getter, but not in eager loading":
     Error: Timeout of 60000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves.
      at listOnTimeout (internal/timers.js:549:17)
      at processTimers (internal/timers.js:492:7)

@sushantdhiman sushantdhiman merged commit 834b9f0 into sequelize:v5 Jun 23, 2020
@sushantdhiman
Copy link
Contributor

🎉 This PR is included in version 5.22.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

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

Successfully merging this pull request may close these issues.

None yet

2 participants