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

Malformed array literal #41

Closed
rbhalla opened this issue Nov 1, 2016 · 4 comments
Closed

Malformed array literal #41

rbhalla opened this issue Nov 1, 2016 · 4 comments

Comments

@rbhalla
Copy link

rbhalla commented Nov 1, 2016

I am trying to update a row with two json columns:

{
  foo: ["bar", "baz"],
  biz: [0, 3]
}

And I get the error Unhandled rejection error: malformed array literal: "[0,3]". Am I missing something fundamental, or is this unintentional?

@ricardogama
Copy link
Collaborator

That should not happen if you registered both attributes on the jsonColumns property, but I guess the error does not come from the plugin.

Can you provide the stack trace and give more information about your setup like what client are you using and if you have extending the initialize and save methods?

@rbhalla
Copy link
Author

rbhalla commented Nov 2, 2016

I am not extending any methods, my model is essentially bare.

export default bookshelf.model('MyModel', bookshelf.Model.extend({
  tableName: 'models'
}, {
  jsonColumns: ['foo', 'biz']
}));

The call stack:

[2] Unhandled rejection error: malformed array literal: "[0,3]"
[2]     at Connection.parseE (/Users/rb/dev/juicebox/app/node_modules/pg/lib/connection.js:539:11)
[2]     at Connection.parseMessage (/Users/rb/dev/juicebox/app/node_modules/pg/lib/connection.js:366:17)
[2]     at Socket.<anonymous> (/Users/rb/dev/juicebox/app/node_modules/pg/lib/connection.js:105:22)
[2]     at emitOne (events.js:96:13)
[2]     at Socket.emit (events.js:188:7)
[2]     at readableAddChunk (_stream_readable.js:177:18)
[2]     at Socket.Readable.push (_stream_readable.js:135:10)
[2]     at TCP.onread (net.js:542:20)
[2] From previous event:
[2]     at Client._query (/Users/rb/dev/juicebox/app/node_modules/knex/lib/dialects/postgres/index.js:179:12)
[2]     at Client.query (/Users/rb/dev/juicebox/app/node_modules/knex/lib/client.js:187:24)
[2]     at Runner.<anonymous> (/Users/rb/dev/juicebox/app/node_modules/knex/lib/runner.js:129:36)
[2] From previous event:
[2]     at /Users/rb/dev/juicebox/app/node_modules/knex/lib/runner.js:55:21
[2] From previous event:
[2]     at Runner.run (/Users/rb/dev/juicebox/app/node_modules/knex/lib/runner.js:41:33)
[2]     at QueryBuilder.Target.then (/Users/rb/dev/juicebox/app/node_modules/knex/lib/interface.js:32:43)
[2]     at QueryBuilder.tryCatcher (/Users/rb/dev/juicebox/app/node_modules/bookshelf/node_modules/bluebird/js/main/util.js:26:23)
[2]     at doThenable (/Users/rb/dev/juicebox/app/node_modules/bookshelf/node_modules/bluebird/js/main/thenables.js:52:38)
[2]     at tryConvertToPromise (/Users/rb/dev/juicebox/app/node_modules/bookshelf/node_modules/bluebird/js/main/thenables.js:30:20)
[2]     at Promise._resolveCallback (/Users/rb/dev/juicebox/app/node_modules/bookshelf/node_modules/bluebird/js/main/promise.js:445:24)
[2]     at Promise._resolveFromSyncValue (/Users/rb/dev/juicebox/app/node_modules/bookshelf/node_modules/bluebird/js/main/method.js:41:14)
[2]     at Sync.update (/Users/rb/dev/juicebox/app/node_modules/bookshelf/node_modules/bluebird/js/main/method.js:17:13)
[2]     at .<anonymous> (/Users/rb/dev/juicebox/app/node_modules/bookshelf/lib/model.js:1009:36)
[2]     at tryCatcher (/Users/rb/dev/juicebox/app/node_modules/bookshelf/node_modules/bluebird/js/main/util.js:26:23)
[2]     at Promise._settlePromiseFromHandler (/Users/rb/dev/juicebox/app/node_modules/bookshelf/node_modules/bluebird/js/main/promise.js:510:31)
[2]     at Promise._settlePromiseAt (/Users/rb/dev/juicebox/app/node_modules/bookshelf/node_modules/bluebird/js/main/promise.js:584:18)
[2]     at Async._drainQueue (/Users/rb/dev/juicebox/app/node_modules/bookshelf/node_modules/bluebird/js/main/async.js:128:12)
[2]     at Async._drainQueues (/Users/rb/dev/juicebox/app/node_modules/bookshelf/node_modules/bluebird/js/main/async.js:133:10)
[2]     at Immediate.Async.drainQueues (/Users/rb/dev/juicebox/app/node_modules/bookshelf/node_modules/bluebird/js/main/async.js:15:14)
[2]     at runCallback (timers.js:570:20)
[2]     at tryOnImmediate (timers.js:550:5)
[2]     at processImmediate [as _immediateCallback] (timers.js:529:5)

@ricardogama
Copy link
Collaborator

ricardogama commented Nov 3, 2016

I'm having an hard time reproducing this error, but I suspect the issue is with the column type and/or the query you're executing. Can you please provide both?

@rbhalla
Copy link
Author

rbhalla commented Nov 3, 2016

@ricardogama I am an idiot. You are right, the first column is json, second is integer[]. I'm guessing this library only works directly with json fields. I'll mark this closed since this is no longer the problem I thought it was, but is there a way to get my array fields stringified before save? (without implementing my own save)

@rbhalla rbhalla closed this as completed Nov 3, 2016
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

No branches or pull requests

2 participants