Skip to content

before() function in post-update policy rules fails with PostgreSQL native enums — operator does not exist: text <> "EnumType" #2727

Description

@ludovicmotte

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions