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

TypeError: Cannot read property 'uuid' of undefined #8125

Closed
axetroy opened this issue Aug 15, 2017 · 6 comments
Closed

TypeError: Cannot read property 'uuid' of undefined #8125

axetroy opened this issue Aug 15, 2017 · 6 comments
Labels

Comments

@axetroy
Copy link
Contributor

axetroy commented Aug 15, 2017

What you are doing?

    const t1: any = await sequelize.transaction();
    try {
      const row: any = await SpendingModel.create(
        {
          uid,
          accession: '00000000-0000-0000-0000-000000000000',
          fromCurrency: 'aa',
          toCurrency: 'bb',
          fromAmount,
          toAmount,
          fee: 0,
          fromFeeAmount,
          toFeeAmount,
          bank: {},
          method: 0,
          type: 0,
          status: 0,
          note: '',
          active: true
        },
        {
          transaction: t
        }
      );

      if (!row) {
        throw new Error(`create fail.`);
      }

      const data: Spending$ = row.dataValues;
      await t1.commit();
      return <Spending$>RFC3339NanoMaper(data);
    } catch (err) {
      await t1.rollback();
      console.error(err);
      throw err;
    }

What do you expect to happen?

It should be created success!

What is actually happening?

Executing (5ee57014-bd5a-452a-a1bb-477c0f5a5675): START TRANSACTION;
Executing (5ee57014-bd5a-452a-a1bb-477c0f5a5675): ROLLBACK;

TypeError: Cannot read property 'uuid' of undefined
    at Query.run (/home/axetroy/gpm/github.com/axetroy/duomi-nodejs/node_modules/sequelize/lib/dialects/postgres/query.js:74:54)
    at retry (/home/axetroy/gpm/github.com/axetroy/duomi-nodejs/node_modules/sequelize/lib/sequelize.js:530:32)
    at /home/axetroy/gpm/github.com/axetroy/duomi-nodejs/node_modules/retry-as-promised/index.js:40:21
    at Promise._execute (/home/axetroy/gpm/github.com/axetroy/duomi-nodejs/node_modules/bluebird/js/release/debuggability.js:300:9)
    at Promise._resolveFromExecutor (/home/axetroy/gpm/github.com/axetroy/duomi-nodejs/node_modules/bluebird/js/release/promise.js:483:18)
    at new Promise (/home/axetroy/gpm/github.com/axetroy/duomi-nodejs/node_modules/bluebird/js/release/promise.js:79:10)
    at retryAsPromised (/home/axetroy/gpm/github.com/axetroy/duomi-nodejs/node_modules/retry-as-promised/index.js:30:10)
    at Promise.try.then.connection (/home/axetroy/gpm/github.com/axetroy/duomi-nodejs/node_modules/sequelize/lib/sequelize.js:530:14)
    at tryCatcher (/home/axetroy/gpm/github.com/axetroy/duomi-nodejs/node_modules/bluebird/js/release/util.js:16:23)
    at Promise._settlePromiseFromHandler (/home/axetroy/gpm/github.com/axetroy/duomi-nodejs/node_modules/bluebird/js/release/promise.js:512:31)
    at Promise._settlePromise (/home/axetroy/gpm/github.com/axetroy/duomi-nodejs/node_modules/bluebird/js/release/promise.js:569:18)
    at Promise._settlePromiseCtx (/home/axetroy/gpm/github.com/axetroy/duomi-nodejs/node_modules/bluebird/js/release/promise.js:606:10)
    at Async._drainQueue (/home/axetroy/gpm/github.com/axetroy/duomi-nodejs/node_modules/bluebird/js/release/async.js:138:12)
    at Async._drainQueues (/home/axetroy/gpm/github.com/axetroy/duomi-nodejs/node_modules/bluebird/js/release/async.js:143:10)
    at Immediate.Async.drainQueues (/home/axetroy/gpm/github.com/axetroy/duomi-nodejs/node_modules/bluebird/js/release/async.js:17:14)
    at runCallback (timers.js:672:20)
    at tryOnImmediate (timers.js:645:5)
    at processImmediate [as _immediateCallback] (timers.js:617:5)

Dialect: postgres
Database version: 9.4
Sequelize version: 4.4.x

@stale stale bot added the stale label Sep 22, 2017
@stale
Copy link

stale bot commented Sep 22, 2017

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If this is still an issue, just leave a comment 🙂

@stale stale bot closed this as completed Sep 29, 2017
@darxtrix
Copy link

darxtrix commented Jul 12, 2018

If the transaction passed is undefined its happens like this, you are passing undefined transaction. The transaction variable is t1 not t i.e { transaction: t }

@virinchimanepalli
Copy link

This problem comes when you are fetching data or doing something using API .inspect the element and chect in the network session there you can see the status . solve according to that . I resolved in this manner

@spmartin823
Copy link

spmartin823 commented Oct 7, 2020

Just wanted to add that this often happens to me when I forget to await the transaction.

// Causes error:
const transaction = sequelize.transaction()
await User.findByPk(1, {transaction})

// Doesn't cause error: 
const transaction = await sequelize.transaction()
await User.findByPk(1, {transaction})

@Qarun-Qadir-Bissoondial

@spmartin823's answer worked for me

@Taqiarzoo
Copy link

Just wanted to add that this often happens to me when I forget to await the transaction.

// Causes error:
const transaction = sequelize.transaction()
await User.findByPk(1, {transaction})

// Doesn't cause error: 
const transaction = await sequelize.transaction()
await User.findByPk(1, {transaction})

Thank You @spmartin823

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

No branches or pull requests

6 participants