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

Incorrect type in entity generation #2335

Open
chungwong opened this issue Aug 21, 2024 · 1 comment
Open

Incorrect type in entity generation #2335

chungwong opened this issue Aug 21, 2024 · 1 comment

Comments

@chungwong
Copy link

Description

character varying(128) in incorrectly generated as 128u32

Steps to Reproduce

Consider the following table

                      Table "public.sessions"
 Column  |          Type          | Collation | Nullable | Default 
---------+------------------------+-----------+----------+---------
 id      | character varying(128) |           | not null | 
 expires | integer                |           |          | 
 session | text                   |           | not null | 
Indexes:
    "sessions_pkey" PRIMARY KEY, btree (id)

id is a session id with length 128 and I believe it is a UUID and hence the 128 length.
With sea-orm-cli generate entity, the type is incorrectly produced.

     type EntityName = Entity;
     fn def(&self) -> ColumnDef {
         match self {
-            Self::Id => ColumnType::Text.def(),
+            Self::Id => ColumnType::String(Some(128u32)).def(),
             Self::Expires => ColumnType::Integer.def().null(),
             Self::Session => ColumnType::Text.def(),
         }

If I don't manually coerce it to ColumnType::Text.def(), it won't compile

   |
59 |             Self::Id => ColumnType::String(Some(128u32)).def(),
   |                         ------------------ ^^^^^^^^^^^^ expected `StringLen`, found `Option<u32>`
   |                         |
   |                         arguments to this enum variant are incorrect
   |
   = note: expected enum `StringLen`
              found enum `std::option::Option<u32>`
note: tuple variant defined here
  --> /home/chung/.cargo/registry/src/index.crates.io-6f17d22bba15001f/sea-query-0.32.0-rc.1/src/table/column.rs:62:5
   |
62 |     String(StringLen),
   |     ^^^^^^

Expected Behavior

After referencing this table, I cannot tell what type should be.

Reproduces How Often

It is always reproducible

Workarounds

Change to ColumnType::Text.def() manually.

Versions

❯ cargo tree | grep sea-
│   ├── sea-orm v1.1.0-rc.1
│   │   ├── sea-orm-macros v1.1.0-rc.1 (proc-macro)
│   │   │   ├── sea-bae v0.2.0 (proc-macro)
│   │   ├── sea-query v0.32.0-rc.1

psql (16.1 (Debian 16.1-1.pgdg100+1), server 9.6.24)
Debian 12

@david-d-h
Copy link

I still have this same issue, anybody looked into this?

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

2 participants