SeaQL / SeaQL/sea-orm

postgresql int2 mapped i8 error

Open
#2,632 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Postgres
Dominant language
Rust
Stars
9.9k
Forks
734
Avg merge
6h 36m
Merged PRs (30d)
8

Description

Description

Steps to Reproduce

  1. define Model
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Serialize, Deserialize)]
#[sea_orm(table_name = "kx_param")]
pub struct Model {
    #[sea_orm(comment = "参数code", primary_key, auto_increment = false)]
    pub param_code: String,
    #[sea_orm(comment = "参数值")]
    pub param_value: Json,
    #[sea_orm(comment = "备注")]
    pub remark: String,
    #[sea_orm(comment = "状态", indexed)]
    pub state: i8,
}
  1. create table use create_table_from_entity ,database will show sql type int2 for column state
  2. insert a row to table
  3. query table rows to Model will show error
Error: Query Error: error occurred while decoding column "state": mismatched types; Rust type `core::option::Option<i8>` (as SQL type `"CHAR"`) is not compatible with SQL type `INT2`

Caused by:
    0: error occurred while decoding column "state": mismatched types; Rust type `core::option::Option<i8>` (as SQL type `"CHAR"`) is not compatible with SQL type `INT2`
    1: error occurred while decoding column "state": mismatched types; Rust type `core::option::Option<i8>` (as SQL type `"CHAR"`) is not compatible with SQL type `INT2`
    2: mismatched types; Rust type `core::option::Option<i8>` (as SQL type `"CHAR"`) is not compatible with SQL type `INT2`
test ctl::param::test_page ... FAILED
Actual Behavior
Reproduces How Often

always

Workarounds

Reproducible Example

Versions

sea-orm v1.1.11

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the reported Model definition and the create_table_from_entity entry point, then reproduce the PostgreSQL int2 decoding error from the listed steps. Trace the i8-to-int2 mapping and add a regression test; done means the row can be inserted and queried into the Model without a type mismatch.

Written by the indexing model from the issue text.

Assessment

Tech stack
postgresql, rust
Domain
databases
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.