Hi,
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 {
type1
type2
type3
}
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
/Users/hideo_kinami/workspace/db-test/node_modules/@redwoodjs/testing/config/jest/api/jest-preset.js:190:64
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 127.0.0.1:5432:5432 postgres:14.4
- Add DATABASE_URL and TEST_DATABASE_URL in the env
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
db-test/api/db/schema.prisma
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}
generator client {
provider = "prisma-client-js"
binaryTargets = "native"
}
enum PostType {
type1
type2
type3
}
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)