From 74799c27b4862e7258865978e74666a7e415997a Mon Sep 17 00:00:00 2001 From: Marc Date: Wed, 5 Apr 2023 18:57:43 +0200 Subject: [PATCH 1/2] fix: parse JSONB --- packages/core/database/lib/dialects/postgresql/index.js | 6 ------ 1 file changed, 6 deletions(-) diff --git a/packages/core/database/lib/dialects/postgresql/index.js b/packages/core/database/lib/dialects/postgresql/index.js index b17c03c6ca..7066a72e0f 100644 --- a/packages/core/database/lib/dialects/postgresql/index.js +++ b/packages/core/database/lib/dialects/postgresql/index.js @@ -22,12 +22,6 @@ class PostgresDialect extends Dialect { 'text', (v) => v ); - // Don't parse JSONB automatically - this.db.connection.client.driver.types.setTypeParser( - this.db.connection.client.driver.types.builtins.JSONB, - 'text', - (v) => v - ); this.db.connection.client.driver.types.setTypeParser( this.db.connection.client.driver.types.builtins.NUMERIC, 'text', From 3ad1e1f7b5fa9ff5b03e9d06cdfb04e4d3e8ccfc Mon Sep 17 00:00:00 2001 From: Marc Date: Wed, 5 Apr 2023 18:58:15 +0200 Subject: [PATCH 2/2] fix: return value if JSON attribute is invalid --- packages/core/database/lib/fields/json.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/core/database/lib/fields/json.js b/packages/core/database/lib/fields/json.js index 8872f2ebbd..1fffcdc101 100644 --- a/packages/core/database/lib/fields/json.js +++ b/packages/core/database/lib/fields/json.js @@ -8,7 +8,12 @@ class JSONField extends Field { } fromDB(value) { - if (typeof value === 'string') return JSON.parse(value); + try { + if (typeof value === 'string') return JSON.parse(value); + } catch (error) { + // Just return the value if it's not a valid JSON string + return value; + } return value; } }