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

Creating afterUpdate hook using the mixin function causes TypeError #3901

curiousdannii opened this Issue Jun 9, 2015 · 3 comments


3 participants

curiousdannii commented Jun 9, 2015

db.Version.addHook( 'afterUpdate', 'update_CurrentVersion', update_CurrentVersion );
db.Version.afterUpdate( 'update_CurrentVersion', update_CurrentVersion );

The first runs correctly, the second causes this error:

Unhandled rejection TypeError: Cannot read property 'length' of undefined
    at /home/dannii/i7el/node_modules/sequelize/lib/hooks.js:125:27
From previous event:
    at Function.each (/home/dannii/i7el/node_modules/sequelize/lib/promise.js:21:17)
    at Hooks.runHooks (/home/dannii/i7el/node_modules/sequelize/lib/hooks.js:120:27)
    at self.sequelize.getQueryInterface.apply.then.tap.then.options.fields.forEach.result._previousDataValues.(anonymous function) (/home/dannii/i7el/node_modules/sequelize/lib/instance.js:672:31)
From previous event:
    at Promise.tap (/home/dannii/i7el/node_modules/sequelize/lib/promise.js:21:17)
    at null.<anonymous> (/home/dannii/i7el/node_modules/sequelize/lib/instance.js:669:10)
From previous event:
    at Promise.then (/home/dannii/i7el/node_modules/sequelize/lib/promise.js:21:17)
    at (/home/dannii/i7el/node_modules/sequelize/lib/instance.js:558:6)
    at Object.<anonymous> (/home/dannii/i7el/web/controllers/extensions.js:175:16)
From previous event:
    at Promise.spread (/home/dannii/i7el/node_modules/sequelize/lib/promise.js:21:17)
    at create (/home/dannii/i7el/web/controllers/extensions.js:143:5)
    at Layer.handle [as handle_request] (/home/dannii/i7el/node_modules/express/lib/router/layer.js:82:5)
    at next (/home/dannii/i7el/node_modules/express/lib/router/route.js:110:13)
    at onFinish (/home/dannii/i7el/node_modules/multer/index.js:211:16)
    at Busboy.<anonymous> (/home/dannii/i7el/node_modules/multer/index.js:188:9)
    at Busboy.emit (events.js:117:20)
    at Busboy.emit (/home/dannii/i7el/node_modules/multer/node_modules/busboy/lib/main.js:31:35)
    at /home/dannii/i7el/node_modules/multer/node_modules/busboy/lib/types/multipart.js:52:13
    at process._tickCallback (node.js:448:13)

@janmeier janmeier added the bug label Jun 9, 2015


This comment has been minimized.


ns3777k commented Jun 17, 2015

From what I see from sources and docs (3rd version), adding a hook like this is not supported.

db.Version.afterUpdate( 'update_CurrentVersion', update_CurrentVersion );

You can pass only callback argument thus it's not a bug. So a quick workaround in your case would be:

db.Version.addHook( 'afterUpdate', 'update_CurrentVersion', update_CurrentVersion );
db.Version.afterUpdate( update_CurrentVersion );

But I guess that would be a good feature to have so I'll implement this.


This comment has been minimized.


curiousdannii commented Jul 11, 2015

@ns3777k Sorry for the false bug report! I mustn't have read the docs carefully enough and just assumed it was the correct usage.


This comment has been minimized.


janmeier commented Jul 11, 2015

@curiousdannii The issue has been fixed , so you can pass a name now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment