You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We are receiving a invalid input syntax for type json error when inserting a string value into a JSONB column on PGSQL using upsertGraph with a payload like: { jsonField: "value" }
Similar to this comment here it seems that if a plain string is used as a value for a JSONB column on PGSQL an error is generated even if the property is in jsonAttributes
To work around this we can do something like this which works but it would be nice to know if there is a supported way or if we are missing something obvious
$beforeInsert() { if (this.jsonField) { this.jsonField = JSON.stringify(this.jsonField); } }
Thanks for building such an awesome orm. Let me know if you need more details or more detailed steps to repeat.
The text was updated successfully, but these errors were encountered:
But there is a contraction in the current behavior in the symmetry between parseJsonAttributes() that always parses the string value and formatJsonAttributes() that only formats if it's an object.
So if you have a JSON string of a JS string in your DB ('"some string"'), reading it will give you a proper JS string as expected ('some string'), but storing this again will now store an invalid JSON string ("some string").
I think removing the isObject() check is the right thing to do, and it will allow people to store all kinds of JSON values, not just objects and arrays.
Hi,
We are receiving a
invalid input syntax for type json
error when inserting a string value into a JSONB column on PGSQL usingupsertGraph
with a payload like:{ jsonField: "value" }
Similar to this comment here it seems that if a plain string is used as a value for a JSONB column on PGSQL an error is generated even if the property is in jsonAttributes
#452 (comment)
It looks like jsonAttributes doesn't stringify the string because it isn't detected as an Object
objection.js/lib/model/modelJsonAttributes.js
Line 38 in 5b76a4c
To work around this we can do something like this which works but it would be nice to know if there is a supported way or if we are missing something obvious
$beforeInsert() { if (this.jsonField) { this.jsonField = JSON.stringify(this.jsonField); } }
Thanks for building such an awesome orm. Let me know if you need more details or more detailed steps to repeat.
The text was updated successfully, but these errors were encountered: