Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] this.serializers does not get updated when adding new array types #469

Open
fgodino-milu opened this issue Dec 13, 2024 · 3 comments · May be fixed by #500
Open

[Bug] this.serializers does not get updated when adding new array types #469

fgodino-milu opened this issue Dec 13, 2024 · 3 comments · May be fixed by #500

Comments

@fgodino-milu
Copy link

Hi all, we've run into an issue when trying to insert arrays of enums into the database because of how array serializers work.

Context
We use typeorm pglite driver to run tests. The PGLite instance gets initiated, we run the db migrations, and then we execute tests.

Reproduction

  1. PGLite instantiates the array serializers using _initArrayTypes
  2. User executes a query like this
CREATE TYPE mood AS ENUM ('sad', 'happy');
CREATE TABLE IF NOT EXISTS test (
    id SERIAL PRIMARY KEY,
    moods mood[]
);
  1. User tries to insert a new record
await db.query(`INSERT INTO test (moods) VALUES ($1);`,[['sad', 'happy']],)
  1. Because the new array type doesn't exist in this.serializers[type.typarray], the query fails to parse the input array into a valid syntax.

Solution

I see two possible solutions:

  1. Add the ability to reprocess the array serializers
  2. Check if there are any new array types to add to the serializer whenever there is a new CREATE type of query.

I'd appreciate any help, I am happy to submit a PR to address the issue.

Thanks!

@sergio-milu
Copy link

hey,

any clue on this issue? this is completely blocking us

thanks!

@samwillis
Copy link
Collaborator

Hey @sergio-milu

Finally catching up!

Just to check, does it work if you crate a PGlite, add the new types, close the database and restart it then try and use the new type?

Obviously this is not ideal...

I think your option one above sounds good to me (exposing the initArrayTypes method), I wouldn't want to add the overhead of checking for new types on each query.

Are you up for having a go at adding this? I'm happy to help walk you through it?

Maybe just make _initArrayTypes public (drop the _) and ensure it can be run multiple times without duplicating the array types.

@fgodino-milu
Copy link
Author

Hey @samwillis, sure. I can submit a PR today

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants