-
-
Notifications
You must be signed in to change notification settings - Fork 611
Closed
Labels
bugSomething isn't workingSomething isn't working
Description
Describe the bug
When calling em.upsert('Book', { SCODE: 'AGSj', title: ['\\'] }), the command fails.
Stack trace
⨯ DriverException: insert into "book" ("scode", "title") values ('AGSj', E'{\\}') on conflict ("scode") do update set "title" = excluded."title" returning "author", "call_number", "discipline", "isbn", "type", "image" - malformed array literal: "{\}"
at PostgreSqlExceptionConverter.convertException ([redacted]/node_modules/@mikro-orm/core/platforms/ExceptionConverter.js:8:16)
at PostgreSqlExceptionConverter.convertException ([redacted]/node_modules/@mikro-orm/postgresql/PostgreSqlExceptionConverter.js:42:22)
at PostgreSqlDriver.convertException (/[redacted]/node_modules/@mikro-orm/core/drivers/DatabaseDriver.js:201:54)
at [redacted]/node_modules/@mikro-orm/core/drivers/DatabaseDriver.js:205:24
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async PostgreSqlDriver.nativeUpdate ([redacted]/node_modules/@mikro-orm/knex/AbstractSqlDriver.js:379:19)
at async SqlEntityManager.upsert ([redacted]/node_modules/@mikro-orm/core/EntityManager.js:496:21)
at async GET (webpack-internal:///(rsc)/./src/app/api/test/route.ts:16:5)
at async [redacted]/node_modules/next/dist/compiled/next-server/app-route.runtime.dev.js:6:62361
previous error: insert into "book" ("scode", "title") values ('AGSj', E'{\\}') on conflict ("scode") do update set "title" = excluded."title" returning "author", "call_number", "discipline", "isbn", "type", "image" - malformed array literal: "{\}"
at Parser.parseErrorMessage ([redacted]/node_modules/pg-protocol/dist/parser.js:287:98)
at Parser.handlePacket ([redacted]/node_modules/pg-protocol/dist/parser.js:126:29)
at Parser.parse ([redacted]/node_modules/pg-protocol/dist/parser.js:39:38)
at Socket.<anonymous> ([redacted]/node_modules/pg-protocol/dist/index.js:11:42)
at Socket.emit (node:events:514:28)
at addChunk (node:internal/streams/readable:343:12)
at readableAddChunk (node:internal/streams/readable:316:9)
at Readable.push (node:internal/streams/readable:253:10)
at TCP.onStreamRead (node:internal/stream_base_commons:190:23)
at TCP.callbackTrampoline (node:internal/async_hooks:130:17) {
length: 119,
severity: 'ERROR',
code: '22P02',
detail: 'Unexpected end of input.',
hint: undefined,
position: '56',
internalPosition: undefined,
internalQuery: undefined,
where: undefined,
schema: undefined,
table: undefined,
column: undefined,
dataType: undefined,
constraint: undefined,
file: 'arrayfuncs.c',
line: '491',
routine: 'ArrayCount'
}
To Reproduce
Steps to reproduce the behavior:
- Upsert data including an array with only a single backslash, e.g.:
em.upsert('Book', { SCODE: 'AGSj', title: ['\\'] })- Observe the error.
Expected behavior
The upsert should perform without errors.
Additional context
- This is likely a PostgreSQL driver-specific issue, with the parser translating JS arrays into Postgres arrays failing.
- Related issue: type: string[] - malformed array literal when setting a value that includes the character "," #3810
- Working patch, can make a PR if this looks good:
diff --git a/node_modules/@mikro-orm/postgresql/PostgreSqlPlatform.js b/node_modules/@mikro-orm/postgresql/PostgreSqlPlatform.js
index 499637a..f8db08d 100644
--- a/node_modules/@mikro-orm/postgresql/PostgreSqlPlatform.js
+++ b/node_modules/@mikro-orm/postgresql/PostgreSqlPlatform.js
@@ -113,7 +113,7 @@ class PostgreSqlPlatform extends knex_1.AbstractSqlPlatform {
return true;
}
marshallArray(values) {
- const quote = (v) => v === '' || v.match(/["{},]/) ? JSON.stringify(v) : v;
+ const quote = (v) => v === '' || v.match(/["{},\\]/) ? JSON.stringify(v) : v;
return `{${values.map(v => quote('' + v)).join(',')}}`;
}
unmarshallArray(value) {Versions
| Dependency | Version |
|---|---|
| node | 20.5.1 |
| typescript | 5.2.2 |
| mikro-orm | 5.8.4 |
| postgres | 15.4 |
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working