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

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

Merged

Conversation

closingin
Copy link
Contributor

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

This bug affects v5 for sure, I haven't checked for v6 but I'm pretty sure it also applies to it.

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:

  1) [POSTGRES] Configuration
       Connections problems should fail with a nice message
         when we don't have the correct server details:
     Error: Timeout of 30000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves. (sequelize/test/integration/configuration.test.js)
      at listOnTimeout (internal/timers.js:549:17)
      at processTimers (internal/timers.js:492:7)

  2) [POSTGRES] Transaction
       autoCallback
         do not rollback if already committed:

      AssertionError: expected 0 to equal 1
      + expected - actual

      -0
      +1
      
      at Proxy.assertEqual (node_modules/chai/lib/chai/core/assertions.js:1026:12)
      at Proxy.methodWrapper (node_modules/chai/lib/chai/utils/addMethod.js:57:25)
      at doAsserterAsyncAndAddThen (node_modules/chai-as-promised/lib/chai-as-promised.js:289:22)
      at Proxy.<anonymous> (node_modules/chai-as-promised/lib/chai-as-promised.js:255:20)
      at Proxy.overwritingMethodWrapper (node_modules/chai/lib/chai/utils/overwriteMethod.js:78:33)
      at Context.<anonymous> (test/integration/transaction.test.js:142:46)
      at runMicrotasks (<anonymous>)
      at processTicksAndRejections (internal/process/task_queues.js:97:5)

PS: I just re-created my PR to target master.

@codecov
Copy link

codecov bot commented Jun 22, 2020

Codecov Report

Merging #12409 into master will increase coverage by 6.15%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #12409      +/-   ##
==========================================
+ Coverage   90.28%   96.44%   +6.15%     
==========================================
  Files          92       95       +3     
  Lines        8968     9110     +142     
==========================================
+ Hits         8097     8786     +689     
+ Misses        871      324     -547     
Impacted Files Coverage Δ
lib/dialects/postgres/query-generator.js 94.93% <100.00%> (ø)
lib/dialects/mssql/connection-manager.js 87.17% <0.00%> (ø)
lib/dialects/mssql/index.js 100.00% <0.00%> (ø)
lib/dialects/mssql/query-interface.js 100.00% <0.00%> (ø)
lib/model.js 96.62% <0.00%> (+0.06%) ⬆️
lib/sequelize.js 95.81% <0.00%> (+0.64%) ⬆️
lib/dialects/abstract/query-generator.js 97.39% <0.00%> (+1.26%) ⬆️
...dialects/abstract/query-generator/helpers/quote.js 100.00% <0.00%> (+6.66%) ⬆️
lib/dialects/mssql/data-types.js 100.00% <0.00%> (+69.87%) ⬆️
lib/dialects/mssql/async-queue.js 100.00% <0.00%> (+76.47%) ⬆️
... and 2 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e33d2bd...cbb3144. Read the comment docs.

@sushantdhiman sushantdhiman merged commit c6e4192 into sequelize:master Jun 23, 2020
@sushantdhiman
Copy link
Contributor

Thanks!

master points to v6, If you want this fix to be released for v5, create a new PR

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

Successfully merging this pull request may close these issues.

None yet

2 participants