When attempting to use model.set I get error "Property 'callback' of object 0..." #13

Closed
thenickofnicks opened this Issue May 6, 2013 · 13 comments

Projects

None yet

2 participants

@thenickofnicks

I am simply using model on the request of "/"

var id1 = model.id()
model.set("collection."+id1, {name:'My name'})

Property 'callback' of object 0,cfed5d48-8422-4dd1-a44f-7e58806f71a6.3,set,collection.b7c6f8f2-1e9a-4b8c-affe-74a5761f5f76,[object Object] is not a function

Owner
SLaks commented May 6, 2013

This sounds like a duplicate of #12; see the solution there.

In particular, check what model.id() returns in the browser.

Does that solve your problem?

If I am using an id created on the server then why can't I set the model? I can see the error you speak of when using model.id() directly on the client at app.ready(), however, If I set my id1 var to be printed on the browser ex.

model.set('_wtf', id1)

app.ready(function(){
console.log(model.get('_wtf'))
})

I get the correct id.

The error is telling me that the id is the correct id?

Owner
SLaks commented May 6, 2013

I'm not sure what you're saying.

Where is your code, and what side is it running on?

/lib/app/index.js

app.get('/', function(page, model) {
    var bson_data = {name:'My name'}
    var id1 = model.id()
    console.log(id1) //logs something like f620c343-f38a-4459-8dea-84a60b4b490d correctly on server

    //here is where i receive error, i am setting the data from here with a var that is correct according to console
    model.set('collection.'+id1, bson_data) 
    //end error

    model.set('_wtf', id1) //set flash var for browser
    page.render('home') //render home view
})

app.ready(function(){
    console.log(model.get('_wtf'))  //logs something like f620c343-f38a-4459-8dea-84a60b4b490d on browser
})
Owner
SLaks commented May 6, 2013

Does that error happen on the server or the browser?
What's the call stack?

The error happens on the server, on the browser I get Internal Server Error.

Callstack:

TypeError: Property 'callback' of object 0,edf9bf79-b1b5-499e-a8ec-b1b6b2544c11.3,set,collection.95df44cf-5fda-4580-aabb-151cfc25cfa3,[object Object] is not a function
    at Object.res.fail (/site/node_modules/racer/lib/txns/txns.Model.js:340:19)
    at /site/node_modules/racer/lib/accessControl/accessControl.Store.js:58:26
    at next (/site/node_modules/racer/lib/middleware.js:7:26)
    at guard (/site/node_modules/racer/lib/accessControl/accessControl.Store.js:217:37)
    at next (/site/node_modules/racer/lib/middleware.js:7:26)
    at Object.run [as guardWrite] (/site/node_modules/racer/lib/middleware.js:10:12)
    at accessController (/site/node_modules/racer/lib/txns/txns.Store.js:106:17)
    at next (/site/node_modules/racer/lib/middleware.js:7:26)
    at Object.run (/site/node_modules/racer/lib/middleware.js:10:12)
    at Model.module.exports.server._commit (/site/node_modules/racer/lib/txns/txns.Model.js:347:29)
    at Model.module.exports.proto._sendOp (/site/node_modules/racer/lib/txns/txns.Model.js:421:12)
    at Model.module.exports.proto.set.fn [as set] (/site/node_modules/racer/lib/mutators/mutators.Model.js:99:21)
    at /site/lib/app/index.js:184:7
    at onRoute (/site/node_modules/derby/lib/derby.server.js:69:7)
    at /site/node_modules/derby/node_modules/tracks/lib/index.js:84:16
    at callbacks (/site/node_modules/derby/node_modules/tracks/node_modules/express/lib/router/index.js:160:37)
    at param (/site/node_modules/derby/node_modules/tracks/node_modules/express/lib/router/index.js:134:11)
    at pass (/site/node_modules/derby/node_modules/tracks/node_modules/express/lib/router/index.js:141:5)
    at Router._dispatch (/site/node_modules/derby/node_modules/tracks/node_modules/express/lib/router/index.js:169:5)
    at Object.middleware [as handle] (/site/node_modules/derby/node_modules/tracks/lib/index.js:48:21)
    at next (/site/node_modules/express/node_modules/connect/lib/proto.js:190:15)
    at /site/node_modules/express/lib/application.js:123:9
    at next (/site/node_modules/derby-auth/node_modules/express/node_modules/connect/lib/proto.js:127:23)
    at pass (/site/node_modules/derby-auth/node_modules/express/lib/router/index.js:107:24)
    at Router._dispatch (/site/node_modules/derby-auth/node_modules/express/lib/router/index.js:170:5)
    at Object.router (/site/node_modules/derby-auth/node_modules/express/lib/router/index.js:33:10)
    at Context.next (/site/node_modules/derby-auth/node_modules/express/node_modules/connect/lib/proto.js:190:15)
    at Context.actions.pass (/site/node_modules/derby-auth/node_modules/passport/lib/passport/context/http/actions.js:77:8)
    at /site/node_modules/derby-auth/node_modules/passport/lib/passport/strategies/session.js:49:12
    at pass (/site/node_modules/derby-auth/node_modules/passport/lib/passport/index.js:307:31)
    at /site/node_modules/derby-auth/node_modules/passport/lib/passport/index.js:318:35
    at /site/node_modules/derby-auth/index.js:87:16
    at pass (/site/node_modules/derby-auth/node_modules/passport/lib/passport/index.js:318:7)
    at Passport.deserializeUser (/site/node_modules/derby-auth/node_modules/passport/lib/passport/index.js:322:5)
    at SessionStrategy.authenticate (/site/node_modules/derby-auth/node_modules/passport/lib/passport/strategies/session.js:41:28)
    at attempt (/site/node_modules/derby-auth/node_modules/passport/lib/passport/middleware/authenticate.js:243:16)
    at Passport.authenticate (/site/node_modules/derby-auth/node_modules/passport/lib/passport/middleware/authenticate.js:244:7)
    at next (/site/node_modules/derby-auth/node_modules/express/node_modules/connect/lib/proto.js:190:15)
    at Passport.initialize (/site/node_modules/derby-auth/node_modules/passport/lib/passport/middleware/initialize.js:69:5)
    at next (/site/node_modules/derby-auth/node_modules/express/node_modules/connect/lib/proto.js:190:15)
    at Object.handle (/site/node_modules/derby-auth/index.js:72:16)
    at next (/site/node_modules/derby-auth/node_modules/express/node_modules/connect/lib/proto.js:190:15)
    at Object.handle (/site/node_modules/derby-auth/node_modules/connect-flash/lib/flash.js:20:5)
    at next (/site/node_modules/derby-auth/node_modules/express/node_modules/connect/lib/proto.js:190:15)
    at Object.expressInit [as handle] (/site/node_modules/derby-auth/node_modules/express/lib/middleware.js:31:5)
    at next (/site/node_modules/derby-auth/node_modules/express/node_modules/connect/lib/proto.js:190:15)
    at Object.query [as handle] (/site/node_modules/derby-auth/node_modules/express/node_modules/connect/lib/middleware/query.js:44:5)
    at next (/site/node_modules/derby-auth/node_modules/express/node_modules/connect/lib/proto.js:190:15)
    at Function.app.handle (/site/node_modules/derby-auth/node_modules/express/node_modules/connect/lib/proto.js:198:3)
    at Object.fn [as handle] (/site/node_modules/express/lib/application.js:119:11)
    at next (/site/node_modules/express/node_modules/connect/lib/proto.js:190:15)
    at next (/site/node_modules/express/node_modules/connect/lib/proto.js:165:78)
    at Object.modelMiddleware [as handle] (/site/node_modules/racer/lib/session/session.Store.js:119:5)
    at next (/site/node_modules/express/node_modules/connect/lib/proto.js:190:15)
    at next (/site/node_modules/racer/node_modules/connect/lib/middleware/session.js:313:9)
    at /site/node_modules/racer/node_modules/connect/lib/middleware/session.js:337:9
    at /site/node_modules/racer/lib/session/session.Store.js:263:11
    at process._tickCallback (node.js:415:13)
Owner
SLaks commented May 6, 2013

This has nothing to do with #12; I mis-read the error.

This is a bug in my fix for derbyjs/racer#126.

The underlying problem is that you didn't create any write access control rules.

I'll fix the bug (you should have gotten a relevent error message) soon.

This happens with access control set to off. Are access control rules enabled by default now?

Owner
SLaks commented May 6, 2013

No; that would mean that I have another bug.

Are you sure?
That sounds like the kind of problem that other people (and unit tests) would have caught.

Looking at the source, the functions in your call stack will only run if access control is enabled.
You also have one access control write rule that did not match this path.

I'm still trying to understand access control completely, so I'll get back to you on that. I never actually set any access control though, so I assume it is disabled, as that's what the docs say.

Unless my usage of derby-auth overrides the default access control, I have not set up any access control.

Owner
SLaks commented May 6, 2013

derby-auth does set up access control.

See https://github.com/lefnire/derby-auth/blob/master/store.js#L136-L138

For production (or production-like) use, you should add your own access control rules for everything that users can write to. See https://github.com/SLaks/racer/tree/master/lib/accessControl#readme

To disable this (and lose all security) when developing, just set those back to false after setting up derby-auth

Owner
SLaks commented May 6, 2013

It looks like the actual bug happens if you call model.set() without a callback, and the set fails.
It tries to call the callback (which originally came from set()), and throws because the callback doesn't exist. (see https://github.com/SLaks/racer/blob/master/lib/txns/txns.Model.js#L340)

I'll change it to throw the error itself if there is no callback. In your particular case, this will work well, because your failure is synchronous. If such a failure happens asynchronously, the entire process will die. (my change will just give a better message)

I understand now, thankyou. After passing overrides to derby-auth all works as expected.

    auth.store(store, myCustomRules(store))

I thought I was overriding before, but it was before derby-auth.

@SLaks SLaks added a commit that closed this issue May 6, 2013
@SLaks Throw original error on failed model sets w/o cb
Fixes #13

Note that asynchronous failed server-side model sets without a callback
will throw an exception that terminates the process.
f7c8d3d
@SLaks SLaks closed this in f7c8d3d May 6, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment