Skip to content

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

Closed

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

Activity

  1. ymc9 commented on Oct 27, 2026

    @ymc9
    Member

    Released in v3.10.0 via #2869.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions