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 · 0 comments

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!

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

No branches or pull requests

1 participant