sequelize: Cannot read property '0' of undefined with pg 7
What you are doing?
I just upgraded to Sequelize 4.4.2 and node-postgres (pg) version 7.0.2
Then, when I call sync() to connecto the db and create tables. I get an error
It happens, for example, when I run this command:
models.sequelize.sync({force: true}).
What do you expect to happen?
Sequelize should connect to Postgres and the create tables.
What is actually happening?
TypeError: Cannot read property 'Symbol(Symbol.iterator)' of undefined
at Promise.then.result (C:\test\node_modules\sequelize\lib\dialects\postgres\connection-manager.js:157:31)
at tryCatcher (C:\test\node_modules\bluebird\js\release\util.js:16:23)
at Promise._settlePromiseFromHandler (C:\test\node_modules\bluebird\js\release\promise.js:512:31)
at Promise._settlePromise (C:\test\node_modules\bluebird\js\release\promise.js:569:18)
at Promise._settlePromise0 (C:\test\node_modules\bluebird\js\release\promise.js:614:10)
at Promise._settlePromises (C:\test\node_modules\bluebird\js\release\promise.js:693:18)
at Async._drainQueue (C:\test\node_modules\bluebird\js\release\async.js:133:16)
at Async._drainQueues (C:\test\node_modules\bluebird\js\release\async.js:143:10)
at Immediate.Async.drainQueues (C:\test\node_modules\bluebird\js\release\async.js:17:14)
at runCallback (timers.js:651:20)
at tryOnImmediate (timers.js:624:5)
at processImmediate [as _immediateCallback] (timers.js:596:5)
__Dialect: postgres __Database version: 9.6.2 (pg 7.0.2) __Sequelize version: 4.4.2
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 53
- Comments: 70 (5 by maintainers)
Commits related to this issue
- chore(npm): update - Add generateFakeData - Add npm scripts - Downgrade pg to 6.4.1 - This is a workaround for `https://github.com/sequelize/sequelize/issues/8043` - Extract jest config from packag... — committed to yszk0123/dali by yszk0123 7 years ago
- chore(npm): update - Add generateFakeData - Add npm scripts - Downgrade pg to 6.4.1 - This is a workaround for `https://github.com/sequelize/sequelize/issues/8043` - Extract jest config from packag... — committed to yszk0123/dali by yszk0123 7 years ago
- downgrade pg to fix Sequelize error https://github.com/sequelize/sequelize/issues/8043 — committed to twobucks/bucketly by shime 7 years ago
- fix: Protect against invalid queryResult This commit prevents javascript exceptions caused by issues described in https://github.com/sequelize/sequelize/issues/8043 This commit DOES NOT fix the un... — committed to stephan-nordnes-eriksen/sequelize by stephan-nordnes-eriksen 7 years ago
- fix: Upgrade pg & sequelize to fix upsert error See sequelize/sequelize#8043 — committed to franky47/stravels-graphql by deleted user 6 years ago
I just installed pg@6.4.1. it may be an issue related with the support for pg ^7.0.2
I found that switching from
findOrCreate
tofindCreateFind
(documentation here) solved this issue for meto anyone who downgraded to 6.4.1 to get around this issue… you should go to 6.4.2 since a security vulnerability was recently patched in some old versions: https://node-postgres.com/announcements
cc: @Anatoly-Ktitarov, @shime , @crabicode , @yszk0123
this happens to me while migration
queryInterface.changeColumn
+1 for a fix for this.
I tried sync: false and commenting out sync all together, but it didnt work
I also tried to work around the upsert error, by just doing an update instead, but the same error still occurs.
The downgrade to 6.4.2 works for me
Please stop posting +1. Emoji responses serve that purpose without sending an email to everyone subscribed for updates.
Hi Guys…Any news on the development of the solution for this issue ? Already 6 months since the beginning of this issue and we had no information about a possible fix of this… Do you plan to support pg7 in a near future ? Thanks in advance for your answers
So, I would say there is a problem as soon as their is more than one query executed at a time. Given the following code:
It outputs with pg 6:
And it outputs with pg 7 :
So the way to access the result is not the same anymore.
In sequelize, after the query completion with the postgres dialect:
https://github.com/sequelize/sequelize/blob/bb25c19b34f47eeec8f3556b087c2926898d5bbd/lib/dialects/postgres/query.js#L97-L99
Sequelize assumes that queryResult is an object, but in fact, if multiple queries were executed, it’s an array.
Hope it’ll help.
Is there any update on this? 😃
I think the downgrade the pg package is not a permament solution because in this case we can loose some new functionalities that new versions of postgresql will give to programmers in time so I think will be best to investigate the code of sequalize in order to match the changes in the package and go to follow those changes instead of avoid them in long run!
similar to @fnando, the issue I’m seeing is when running raw queries with multiple statements, where the
rows
param is now aResult
array containingrows
and the first result was emptythx @Anatoly-Ktitarov for quick fix, can confirm was on 7.0.2 and downgrading pg to 6.4.1 works
+1
I’m getting the same error when running
sync({force: true})
on postgres 9.6.5Without testing on other conditions (complex queries or other cases) I found a solution that works on pg:latest and don’t give an error during init, because the @Anatoly-Ktitarov solution fail on project startup because queryResult is an array and doesn’t have a rows property. Change line 98 of query.js
I think the solution not cover all cases, because some queries could have more than two or three results inside and you would need to access other.
But at the moment, it works for me.
This is amazing! Thanks!
A lot of people are upgrading to pg@7 this weekend 😁 Thanks @sushantdhiman!!
I’m also seeing this while using
sync({ force: true })
in sequelize v4.20.1 with PostgreSQL server 10 running on Windows. The workaround of downgradingpg
to6.4.2
worked for me as well.I get this as well, I can solve it by checking that the rows array exists in query.js:112
+1 for this, had to downgrade pg to 6.4.2 to fix our production app
Just ran into the same issue with
MyModel.upsert()
-> TypeError: Cannot read property ‘0’ of undefined
versions:
no solution so far?
still seeing this problem with
pg@7.2.0
as well… as @morficus said,6.4.2
is the correct and last version that does not have this issue.We get the following exception:
This happens when using sequelize to run a DB migration which creates some tables using a blob of raw SQL. Making the change mentioned here https://github.com/sequelize/sequelize/issues/8043#issuecomment-319499298 fixes it. But obviously we can’t make that change everywhere so we’ve had to downgrade to 6.4.2 for now.
+1
I have the same problem with “pg”: “^ 7.4.0” what is the milestone of this?
Hi Guys…I’m having this issue too. For me, it happens when using the method “upsert”.
Using pg@6.4.2 does not trigger the error…
Do you have any news about a possible fix for this ? Thank you very much for your answer
Mine throws right after
db.sequelize.sync
&findOrCreate
are invoked. However when commentingdb.sequelize.sync
& calling justfindOrCreate
it worked.Hm…
I’m still having this problem on pg 7.4.1
I ran into this while trying to create an index. Downgrading from pg@7.3.0 to 6.4.2 made the error go away.
@farzd transaction is a term that is not specific to Sequelize.
What is a database transaction how to do Sequelize transactions
I just got this error and the code is something like this:
And this is the backtrace:
Diff:
@dsullivan7 thank you for the fix. Worked for me as well…
Is there an update here? I’m running into this issue when I try
Model.upsert(args)
.@Anatoly-Ktitarov thanks, that fixed for me…
but still looking to this being resolved any time soon