sea-orm-cli generates Option<String> instead of Option<PgLtree>
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 9.9k
- Forks
- 735
- Avg merge
- 6h 36m
- Merged PRs (30d)
- 8
Description
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
- Create a PostgreSQL database schema with a table using a nullable ltree column
- Use sea-orm-cli to convert the schema
- 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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the sea-orm-cli generate entity command and trace how PostgreSQL column types are mapped for nullable ltree columns. Compare the generated entity with the reported PgLtree and Eq errors; done means the generated entity uses a compatible type and querying the table succeeds.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- postgresql, rust
- Domain
- databases
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100