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

sea-orm-cli generates Option<String> instead of Option<PgLtree> #2456

Open
thefiddler opened this issue Dec 18, 2024 · 0 comments
Open

sea-orm-cli generates Option<String> instead of Option<PgLtree> #2456

thefiddler opened this issue Dec 18, 2024 · 0 comments

Comments

@thefiddler
Copy link

thefiddler commented Dec 18, 2024

Description

I am using sea-orm-cli to autogenerate entities from my existing PostgreSQL schema:

sea-orm-cli generate entity \
  --output-dir src/entities \
  --database-url "$DATABASE_URL" \
  --with-serde both \
  --serde-skip-deserializing-primary-key \
  --expanded-format

This worked perfectly fine, until I tried to use a table with an ltree column.

The autogenerated entity is using an Option<String> instead of Option<PgLtree>, which then fails to deserialize with an sqlx error:

DatabaseError(Query(SqlxError(ColumnDecode { index: "\"history\"", source: "mismatched types; Rust type `core::option::Option<alloc::string::String>` (as SQL type `TEXT`) is not compatible with SQL type `ltree`" })))

The entity looks like this:

#[derive(Clone, Debug, PartialEq, DeriveModel, DeriveActiveModel, Eq, Serialize, Deserialize)]
pub struct Model {
    #[serde(skip_deserializing)]
    pub id: i32,
    pub history: Option<String>,
    pub created_at: Option<DateTimeWithTimeZone>,
    pub updated_at: Option<DateTimeWithTimeZone>,
    pub deleted_at: Option<DateTimeWithTimeZone>,
}

Steps to Reproduce

  1. Create a PostgreSQL database schema with a table using a nullable ltree column
  2. Use sea-orm-cli to convert the schema
  3. Try to query the table

Expected Behavior

sea-orm-cli creates an entity using the PgLtree type. Querying the entity succeeds.

Actual Behavior

sea-orm-cli creates an entity using the String (TEXT) type. Querying the entity fails.

Reproduces How Often

100% of the time.

Workarounds

I have looked into the documentation and tried the various sea-orm-cli options, but none of them made any difference.

I tried manually editing the generated entity to switch String->PgLtree, but then it does not compile:

the trait bound `sea_orm::sqlx::sqlx_postgres::types::PgLTree: std::cmp::Eq` is not satisfied
the trait `std::cmp::Eq` is implemented for `std::option::Option<T>`
required for `std::option::Option<sea_orm::sqlx::sqlx_postgres::types::PgLTree>` to implement `std::cmp::Eq`

Reproducible Example

Versions

Tested with the latest version 1.1.2

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