V3: 'cached plan must not change result type' error by Enum definition on Postgres.


I’m faced with ‘cached plan must not change result type’ error on Postgres DB with redwood 3.0.1.
It will reproduce when Prisma schema has an Enum type definition, and runs the yarn test several times.

Are there any resolution for it?

  • The schema is
enum PostType {

model Post {
  id       String    @id @default(uuid())
  title    String?
  postType PostType?

  createdAt DateTime @default(now())

'yarn test` results are

FAIL   api  api/src/services/posts/posts.test.ts
  ● posts › returns all posts

    Invalid `getProjectDb()[model].create()` invocation in

      187     createArgs(scenarios)
      188   )
      189 } else {
    → 190   scenarios[model][name] = await getProjectDb()[model].create(
    Error occurred during query execution:
    ConnectorError(ConnectorError { user_facing_error: None, kind: QueryError(Error { kind: Db, cause: Some(DbError { severity: "ERROR", parsed_severity: Some(Error), code: SqlState(E0A000), message: "cached plan must not change result type", detail: None, hint: None, position: None, where_: None, schema: None, table: None, column: None, datatype: None, constraint: None, file: Some("plancache.c"), line: Some(718), routine: Some("RevalidateCachedQuery") }) }) })

      at RequestHandler.handleRequestError (node_modules/@prisma/client/runtime/index.js:29913:13)
      at RequestHandler.request (node_modules/@prisma/client/runtime/index.js:29892:12)
      at PrismaClient._request (node_modules/@prisma/client/runtime/index.js:30864:16)
      at seedScenario (node_modules/@redwoodjs/testing/config/jest/api/jest-preset.js:190:36)
      at Object.<anonymous> (node_modules/@redwoodjs/testing/config/jest/api/jest-preset.js:142:28)

and DB logs are

2022-09-24 00:28:16.773 UTC [78] ERROR:  cached plan must not change result type
2022-09-24 00:28:16.773 UTC [78] STATEMENT:  SELECT "public"."Post"."id", "public"."Post"."title", "public"."Post"."postType", "public"."Post"."createdAt" FROM "public"."Post" WHERE "public"."Post"."id" = $1 LIMIT $2 OFFSET $3 /* traceparent=00-00-00-00 */

Reproduce steps

Followings are reproduce steps.

  • Create a redwood app
yarn create redwood-app --ts ./db-test
cd ./db-test
  • Run postgres docker container
docker run --rm -it -e POSTGRES_PASSWORD=postgres -e POSTGRES_DB=app -p postgres:14.4
echo '' >> .env.defaults
echo 'DATABASE_URL=postgresql://postgres:postgres@localhost:5432/app' >> .env.defaults
echo 'TEST_DATABASE_URL=postgresql://postgres:postgres@localhost:5432/app' >> .env.defaults
  • Edit Prisma schema


datasource db {
  provider = "postgresql"
  url      = env("DATABASE_URL")

generator client {
  provider      = "prisma-client-js"
  binaryTargets = "native"

enum PostType {

model Post {
  id       String    @id @default(uuid())
  title    String?
  postType PostType?

  createdAt DateTime @default(now())
  • Migrate DB for the schema
yarn rw prisma migrate dev
  • Generate scaffold to create some tests for the Post
yarn rw g scaffold Post
  • Run the tests several times.
    • First execution is passed, but next execution will fail
yarn rw test
  (type 'a' to re-execute all)

The issue was resolved on Redwood version 3.0.2.

It seems it was related to this change

Thank you for the team’s effort!

1 Like