pg-mem icon indicating copy to clipboard operation
pg-mem copied to clipboard

Unable to parse multi values Enum array to string

Open ash67 opened this issue 2 years ago • 1 comments

Describe the bug

I have multi value enum array which should be parsed as {value1, value2} but they are being parsed as ['value1', 'value2'] hence Typeorm throws error in this file .

(pg-mem tries to throw nice error messages when possible... so paste it here if you have one !)

The error is thrown by Typeorm

image

To Reproduce

Query Results with Pg-mem:

{
        listings_id: 'list_OG2fN5IUruoft0Mh',
        listings_created: 2021-08-16T00:05:57.000Z,
        listings_updated: 2022-04-19T09:51:25.975Z,
        listings_deactivated: null,
        listings_deleted: null,
        listings_type: 'Product',
        listings_currency: 'USD',
        listings_tags: [ 'Sold' ]
     }

Query results with Typeorm repository

 {
    listings_id: 'list_OG2fN5IUruoft0Mh',
    listings_created: 2021-08-16T00:05:57.000Z,
    listings_updated: 2022-04-19T09:51:25.975Z,
    listings_deactivated: null,
    listings_deleted: null,
    listings_type: 'Product',
    listings_currency: 'USD',
    listings_tags: '{Sold}'
  }

"If possible, paste here (including create table statements) a query that fails on https://oguimbal.github.io/pg-mem-playground/, but suceeds when ran on an actual PG database"

pg-mem version

2.4.3

(nb: the version in your package.json version is often not precise enough... please run "cat ./node_modules/pg-mem/package.json | grep version" to tell which minor version is actually installed)

ash67 avatar May 24 '22 01:05 ash67

I'm seeing this as well in 2.5.0

cameronbell avatar Jun 12 '22 18:06 cameronbell

It's because node-postgres doesn't parse enum arrays by default brianc/node-pg-types#56. @oguimbal Is there a way to disable parsing of enum arrays?

Thore1954 avatar Dec 05 '22 10:12 Thore1954

Running into this problem, as well.

MyNameIsOka avatar Dec 20 '22 05:12 MyNameIsOka

This is blocking us from using it with Typeorm. @oguimbal can anything be done about this?

Suall1969 avatar Mar 30 '23 10:03 Suall1969

Hi, i'll see if I can reproduce it.

This problem is not straightforward for me, since I never used enums with typeorm...

To help, can you provide a:

  • create enum + create table statements
  • a typeorm entity with that enum that triggers this problem

in order to help me create a unit test ?

(or just a typeorm entity that will automatically create the right schema)

Thanks

oguimbal avatar Mar 31 '23 08:03 oguimbal

Thank you @oguimbal I created this repo: https://github.com/suall1969/pg-mem-typeorm-enum-array-issue

Suall1969 avatar Mar 31 '23 13:03 Suall1969

That's perfect, thanks for the effort :)

Fixed in [email protected]

oguimbal avatar Mar 31 '23 15:03 oguimbal