Cast issues with enums
SteelAlloy opened this issue · 1 comments
The following issue is a repost of SeaQL/sea-orm#1527, since this issue actually belongs here.
I've also encountered the bug with
gte
: `"operator does not exist: some_enum >= text".
Description
.is_in(...)
and .is_not_in(...)
don't use CAST when comparing enums.
gte
as well and other operators I guess.
Steps to Reproduce
- Create a table in Postgres, that has a field with custom type as enum.
- Make a query to that table, having a condition of this enum field IN vector.
Expected Behavior
The same as with .eq
, .ne
operators. Resulting query should look something like this.
-- For .eq operator, it generates correctly
WHERE "table"."enum_field" = CAST($1 AS enum_type)
-- For .is_in operator, it generates a different query without CAST
WHERE "table"."enum_field" IN (CAST($1 AS enum_type), CAST($2 AS enum_type))
Actual Behavior
Generated query looks something like this
WHERE "table"."enum_field" IN ($1, $2)
PgDatabaseError
is returned.
{severity: Error, code: "42883", message: "operator does not exist: enum_type <> text", ...}
Reproduces How Often
Always, I assume. But the bug was spoted when in subquery.
Versions
sea-orm v0.11.0
postgres
macos Ventura
sea-orm v0.12.1
postgres
ubuntu 22
Additional Information
cc @0xAndoroid
I think this is a bug only in SeaORM, as all cast as
is applied by the ORM. I don't think there is any limitation in SeaQuery.