Skip to content

type: string[] - malformed array literal when setting a value that includes the character "," #3810

@tronikelis

Description

@tronikelis

Describe the bug
When updating the values of a property that is an array of strings, the orm does not escape "," which leads to breaking behavior. This is probably related to #3037

My property

@Property({ type: "string[]", default: defaults.options })
options = defaults.options;

Relevant failing query:

update "ExamSimQuestions" set "options" = '{Example optionadad,comma at the end,}', "updatedAt" = '2022-12-01T17:18:18.573Z' where "id" = 124

Stack trace

DriverException: update \"ExamSimQuestions\" set \"options\" = '{Example optionadad,Example text,Example text,Example text,,,,,}', \"updatedAt\" = '2022-12-01T16:56:35.435Z' where \"id\" = 124 - malformed array literal: \"{Example optionadad,Example text,Example text,Example text,,,,,}\"
    at PostgreSqlExceptionConverter.convertException (C:\\Users\\bdona\\Downloads\\coding\\tronikel.training-mikro-orm\ode_modules\\@mikro-orm\\core\\platforms\\ExceptionConverter.js:8:16)
    at PostgreSqlExceptionConverter.convertException (C:\\Users\\bdona\\Downloads\\coding\\tronikel.training-mikro-orm\ode_modules\\@mikro-orm\\postgresql\\PostgreSqlExceptionConverter.js:42:22)
    at PostgreSqlDriver.convertException (C:\\Users\\bdona\\Downloads\\coding\\tronikel.training-mikro-orm\ode_modules\\@mikro-orm\\core\\drivers\\DatabaseDriver.js:192:54)
    at C:\\Users\\bdona\\Downloads\\coding\\tronikel.training-mikro-orm\ode_modules\\@mikro-orm\\core\\drivers\\DatabaseDriver.js:196:24
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async PostgreSqlDriver.nativeUpdate (C:\\Users\\bdona\\Downloads\\coding\\tronikel.training-mikro-orm\ode_modules\\@mikro-orm\\knex\\AbstractSqlDriver.js:326:19)
    at async ChangeSetPersister.persistManagedEntity (C:\\Users\\bdona\\Downloads\\coding\\tronikel.training-mikro-orm\ode_modules\\@mikro-orm\\core\\unit-of-work\\ChangeSetPersister.js:137:21)
    at async ChangeSetPersister.executeUpdates (C:\\Users\\bdona\\Downloads\\coding\\tronikel.training-mikro-orm\ode_modules\\@mikro-orm\\core\\unit-of-work\\ChangeSetPersister.js:42:13)
    at async ChangeSetPersister.runForEachSchema (C:\\Users\\bdona\\Downloads\\coding\\tronikel.training-mikro-orm\ode_modules\\@mikro-orm\\core\\unit-of-work\\ChangeSetPersister.js:68:13)
    at async UnitOfWork.commitUpdateChangeSets (C:\\Users\\bdona\\Downloads\\coding\\tronikel.training-mikro-orm\ode_modules\\@mikro-orm\\core\\unit-of-work\\UnitOfWork.js:742:9)

previous error: update \"ExamSimQuestions\" set \"options\" = '{Example optionadad,Example text,Example text,Example text,,,,,}', \"updatedAt\" = '2022-12-01T16:56:35.435Z' where \"id\" = 124 - malformed array literal: \"{Example optionadad,Example text,Example text,Example text,,,,,}\"
    at Parser.parseErrorMessage (C:\\Users\\bdona\\Downloads\\coding\\tronikel.training-mikro-orm\ode_modules\\pg-protocol\\dist\\parser.js:287:98)
    at Parser.handlePacket (C:\\Users\\bdona\\Downloads\\coding\\tronikel.training-mikro-orm\ode_modules\\pg-protocol\\dist\\parser.js:126:29)
    at Parser.parse (C:\\Users\\bdona\\Downloads\\coding\\tronikel.training-mikro-orm\ode_modules\\pg-protocol\\dist\\parser.js:39:38)
    at Socket.<anonymous> (C:\\Users\\bdona\\Downloads\\coding\\tronikel.training-mikro-orm\ode_modules\\pg-protocol\\dist\\index.js:11:42)
    at Socket.emit (node:events:513:28)
    at addChunk (node:internal/streams/readable:324:12)
    at readableAddChunk (node:internal/streams/readable:297:9)
    at Readable.push (node:internal/streams/readable:234:10)
    at TCP.onStreamRead (node:internal/stream_base_commons:190:23)

To Reproduce
Steps to reproduce the behavior:

  1. Create an entity with a property that has the type "string[]"
  2. Try to insert values that have "," into the array
  3. "," is not escaped, producing malformed array literal

Expected behavior
Every string in the array should be escaped, or at least the "," character

Additional context
Add any other context about the problem here.

Versions

Dependency Version
node 18.12.0
typescript 4.9.3
mikro-orm 5.5.3
your-driver postgres

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions