SeaQL / SeaQL/sea-orm

sea-orm-cli generates incorrect model for Postgres database containing 'tsvector' columns

Open
#2,750 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

S-blocked
Dominant language
Rust
Stars
9.9k
Forks
735
Avg merge
6h 36m
Merged PRs (30d)
8

Description

Discussed in https://github.com/SeaQL/sea-orm/discussions/1880

Originally posted by flyaruu February 18, 2023

Description

I'm using a postgres data model I tend to use for demos (some fictional data about movie rentals), and one of the tables has a column of type 'tsvector'

When I generate the ORM source, it looks like this:

#[sea_orm(column_type = "custom(\"tsvector\")")]
pub fulltext: String,

(The data + data model is open source, available here: but I don't think it is anything special.

When querying a record of this type I get this panic:

thread 'tokio-runtime-worker' panicked at 'called `Result::unwrap()` on an `Err` value: Query(SqlxError(ColumnDecode { index: "\"fulltext\"", source: "mismatched types; Rust type `core::option::Option<alloc::string::String>` (as SQL type `TEXT`) is not compatible with SQL type `tsvector`" }))',

So it looks like String isn't the right type, but I'm unsure what is, and if sqlx supports it at all. I can comment out this column for now, then it all works.

But I'd say it would be better to ignore this type, as it breaks the entire table.

Steps to Reproduce

  1. Take a database containing a tsvector column (e.g. the docker image I reference)
  2. Generate a model using sea-orm-cli
  3. Query one record (I did a find_by_id, but I don't think it matters)
  4. Panic!
Expected Behavior

The result of that type

Actual Behavior

A panic

Reproduces How Often

Always

Versions

├── sea-orm v0.11.0
│   ├── sea-orm-macros v0.11.0 (proc-macro)
│   ├── sea-query v0.28.3
│   │   ├── sea-query-derive v0.3.0 (proc-macro)
│   ├── sea-query-binder v0.3.0
│   │   ├── sea-query v0.28.3 (*)
│   ├── sea-strum v0.23.0
│   │   └── sea-strum_macros v0.23.0 (proc-macro)

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 sea-orm-cli model generation flow and reproduce the issue against a PostgreSQL table containing a tsvector column, then query the generated model. Compare the generated String mapping with the reported SQLx decode error; done means generation no longer makes the table fail when this column is queried, either by supporting the type or safely ignoring it.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.