encoredev / encore

Open Source Development Platform for building robust type-safe distributed systems with declarative infrastructure
https://encore.dev
Mozilla Public License 2.0
7.76k stars 330 forks source link

[BUG?] Issue parsing postgres ENUM types in rust daemon #1546

Open nich-frai opened 3 weeks ago

nich-frai commented 3 weeks ago

[BUG?] Parsing custom postgres ENUM types in Rust daemon


How to reproduce:

  1. Create a migration using postgres native ENUM type:

    CREATE TYPE some_enum as ENUM ('value1','value2','value3');
    CREATE TABLE some_table (
    id SERIAL PRIMARY KEY,
    use_enum some_enum DEFAULT 'value1'
    );
  2. Use the native dabatabse client provided by encore

    
    import { SQLDatabase } from "encore.dev/storage/sqldb";

export const db = new SQLDatabase("some_db", { migrations : "./migrations"});


3. Try to query using this connection/client
```ts
const row = db.queryRow`
SELECT 
      id, use_enum  
    FROM 
      some_table
`;

At this point the rust daemon fails with the following message:

An internal error occurred.: unable to parse column use_enum: Error {
   kind: FromSql(0,),
   cause: Some( WrongType {
      postgres: Other(
         Other {
            name: \"use_enum\",
            oid: 16847,
            kind: Enum([
               \"value1\",
               \"value2\",
               \"value3\",
            ],),
            schema: \"public\",
        },
      ),
      rust: \"encore_runtime_core::sqldb::val::RowValue\",
   },),
}

Inserting into the table/database does not reproduce this error, only while parsing/selecting from it!

Environment

Just ask if any other information would help!

mdauthentic commented 1 day ago

I'm having a similar issue with postgres Enum. Mine failed with the following message.

node:internal/process/promises:394
    triggerUncaughtException(err, true /* fromPromise */);
    ^

[Error: error serializing parameter 1: cannot convert between the Rust type `encore_runtime_core::sqldb::val::RowValue` and the Postgres type `user_role`] {
  code: 'GenericFailure'
}
eandre commented 1 day ago

Thanks for the report. Will take a look at fixing this tomorrow. In the meantime you can work around it by casting the column to text SELECT my_enum::text [...].