Description and expected behavior
When using before() in @@deny("post-update", ...) policy rules to compare a PostgreSQL enum field's previous value against its current value, the generated SQL casts the $before values as text. PostgreSQL rejects the comparison because the column is a native enum type and there's no implicit <> operator between text and a custom enum.
Error: 42883 — operator does not exist: text <> "StateType"
Reproduction:
enum StateType {
PREAMBLE
IN_PROGRESS
DONE
REVIEWED
}
model Post {
id String @id @default(uuid())
state StateType @default(PREAMBLE)
@@deny("post-update", before().state != state && (
before().state == PREAMBLE && state != IN_PROGRESS ||
before().state == IN_PROGRESS && state != DONE && state != PREAMBLE ||
before().state == DONE && state != REVIEWED ||
before().state == REVIEWED && state != DONE))
}
Generated SQL (problematic part):
select COUNT(1) = $1 as "$condition"
from "public"."Assessment"
left join (
select cast("$values"."column1" as uuid) as "id",
cast("$values"."column2" as text) as "state" -- ← cast as text, should be "StateType"
from (VALUES ($2, $3)) as "$values"
) as "$before" on "Assessment"."id" = "$before"."id"
where "Assessment"."id" = $4
and coalesce("$before"."state" != "Assessment"."state" and (...), false) = false
-- ^^^^ text ^^^^ "StateType" enum → operator does not exist
Environment (please complete the following information):
- ZenStack version: 3.8.0
- Database type: Postgresql
- Node.js version: 24.x
- Package manager: npm
Description and expected behavior
When using before() in @@deny("post-update", ...) policy rules to compare a PostgreSQL enum field's previous value against its current value, the generated SQL casts the $before values as text. PostgreSQL rejects the comparison because the column is a native enum type and there's no implicit <> operator between text and a custom enum.
Error: 42883 — operator does not exist: text <> "StateType"
Reproduction:
Generated SQL (problematic part):
Environment (please complete the following information):