prisma: The `ConnectorError` `cached plan must not change result type` periodically appears (Postgres).
Bug description
I’ve got several test suites for the graphql API (built with ApolloServer & Prisma). The tests basically run some queries against the API endpoint with the apollo client. They are standalone (imitate user queries to the API). API uses a dev database (local Postgres docker container) and a locally running server.
An error occurs periodically, I can run 1 test file a few times and it passes, then this error occurs, after that again the tests pass.
console.error src/tests/utils/ErrorLog.ts:7
Exception: {
errors: [
{
message: '\n' +
'Invalid `prisma.company.create()` invocation:\n' +
'\n' +
'\n' +
' Error occurred during query execution:\n' +
'ConnectorError(ConnectorError { user_facing_error: None, kind: QueryError(Error { kind: Db, cause: Some(DbError { severity: "ERROR", parsed_severity: Some(Error), code: SqlState("0A000"), 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(722), routine: Some("RevalidateCachedQuery") }) }) })',
locations: [],
path: [Array]
}
],
stacktrace: [
'Error: ',
'Invalid `prisma.company.create()` invocation:',
'',
'',
' 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("0A000"), 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(722), routine: Some("RevalidateCachedQuery") }) }) })',
' at new CombinedError (/Users/jackiejo/main/smidyo/smidyo-monorepo/quoting-portal/api/node_modules/apollo-server/node_modules/graphql-tools/src/stitching/errors.ts:90:5)',
' at Object.checkResultAndHandleErrors (/Users/jackiejo/main/smidyo/smidyo-monorepo/quoting-portal/api/node_modules/apollo-server/node_modules/graphql-tools/src/stitching/errors.ts:111:11)',
' at CheckResultAndHandleErrors.transformResult (/Users/jackiejo/main/smidyo/smidyo-monorepo/quoting-portal/api/node_modules/apollo-server/node_modules/graphql-tools/src/transforms/CheckResultAndHandleErrors.ts:15:12)',
' at /Users/jackiejo/main/smidyo/smidyo-monorepo/quoting-portal/api/node_modules/apollo-server/node_modules/graphql-tools/src/transforms/transforms.ts:37:45',
' at Array.reduce (<anonymous>)',
' at applyResultTransforms (/Users/jackiejo/main/smidyo/smidyo-monorepo/quoting-portal/api/node_modules/apollo-server/node_modules/graphql-tools/src/transforms/transforms.ts:35:21)',
' at /Users/jackiejo/main/smidyo/smidyo-monorepo/quoting-portal/api/node_modules/apollo-server/node_modules/graphql-tools/src/stitching/delegateToSchema.ts:104:12',
' at step (/Users/jackiejo/main/smidyo/smidyo-monorepo/quoting-portal/api/node_modules/apollo-server/node_modules/graphql-tools/dist/stitching/delegateToSchema.js:32:23)',
' at Object.next (/Users/jackiejo/main/smidyo/smidyo-monorepo/quoting-portal/api/node_modules/apollo-server/node_modules/graphql-tools/dist/stitching/delegateToSchema.js:13:53)',
' at fulfilled (/Users/jackiejo/main/smidyo/smidyo-monorepo/quoting-portal/api/node_modules/apollo-server/node_modules/graphql-tools/dist/stitching/delegateToSchema.js:4:58)'
]
}
OR this error occurs if some tests pass in the suite
console.error src/tests/utils/ErrorLog.ts:7
Exception: {
errors: [
{
message: '\n' +
'Invalid `prisma.salesDomain.create()` invocation:\n' +
'\n' +
'\n' +
' Error occurred during query execution:\n' +
'ConnectorError(ConnectorError { user_facing_error: None, kind: QueryError(Error { kind: Db, cause: Some(DbError { severity: "ERROR", parsed_severity: Some(Error), code: SqlState("0A000"), 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(722), routine: Some("RevalidateCachedQuery") }) }) })',
locations: [],
path: [Array]
}
],
stacktrace: [
'Error: ',
'Invalid `prisma.salesDomain.create()` invocation:',
'',
'',
' 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("0A000"), 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(722), routine: Some("RevalidateCachedQuery") }) }) })',
' at new CombinedError (/Users/jackiejo/main/smidyo/smidyo-monorepo/quoting-portal/api/node_modules/apollo-server/node_modules/graphql-tools/src/stitching/errors.ts:90:5)',
' at Object.checkResultAndHandleErrors (/Users/jackiejo/main/smidyo/smidyo-monorepo/quoting-portal/api/node_modules/apollo-server/node_modules/graphql-tools/src/stitching/errors.ts:111:11)',
' at CheckResultAndHandleErrors.transformResult (/Users/jackiejo/main/smidyo/smidyo-monorepo/quoting-portal/api/node_modules/apollo-server/node_modules/graphql-tools/src/transforms/CheckResultAndHandleErrors.ts:15:12)',
' at /Users/jackiejo/main/smidyo/smidyo-monorepo/quoting-portal/api/node_modules/apollo-server/node_modules/graphql-tools/src/transforms/transforms.ts:37:45',
' at Array.reduce (<anonymous>)',
' at applyResultTransforms (/Users/jackiejo/main/smidyo/smidyo-monorepo/quoting-portal/api/node_modules/apollo-server/node_modules/graphql-tools/src/transforms/transforms.ts:35:21)',
' at /Users/jackiejo/main/smidyo/smidyo-monorepo/quoting-portal/api/node_modules/apollo-server/node_modules/graphql-tools/src/stitching/delegateToSchema.ts:104:12',
' at step (/Users/jackiejo/main/smidyo/smidyo-monorepo/quoting-portal/api/node_modules/apollo-server/node_modules/graphql-tools/dist/stitching/delegateToSchema.js:32:23)',
' at Object.next (/Users/jackiejo/main/smidyo/smidyo-monorepo/quoting-portal/api/node_modules/apollo-server/node_modules/graphql-tools/dist/stitching/delegateToSchema.js:13:53)',
' at fulfilled (/Users/jackiejo/main/smidyo/smidyo-monorepo/quoting-portal/api/node_modules/apollo-server/node_modules/graphql-tools/dist/stitching/delegateToSchema.js:4:58)'
]
}
Also this periodically appears on postgres log in docker
dev-postgres_postgres_1 | 2021-06-15 14:09:35.072 UTC [35] ERROR: cached plan must not change result type
How to reproduce
Please refer to this repository: https://github.com/JackieJoo/prisma-error-sample
Expected behavior
No response
Prisma information
Environment & setup
- OS: Mac OS
- Database: PostgreSQL
- Node.js version: v14.15.1
Prisma Version
2.24.1
About this issue
- Original URL
- State: open
- Created 3 years ago
- Reactions: 12
- Comments: 23 (10 by maintainers)
Commits related to this issue
- Try to work around "cached plan must not change result type" errors. Using the workaround described in https://github.com/prisma/prisma/issues/7678. — committed to jyasskin/cookbook by jyasskin a year ago
- Try to work around "cached plan must not change result type" errors. Using the workaround described in https://github.com/prisma/prisma/issues/7678. — committed to jyasskin/cookbook by jyasskin a year ago
I received this error when I had applied a migration to my dev DB, which reset the DB, but my server had not been restarted.
Is there any news on this thread?
this happens after reseting the database with
prisma migrate resetand an app is still running.in our case we have a reset job that runs on test environments to reset the database.
I can reproduce this after running the reproduction twice.
It doesn’t seem to happen if I add
&statement_cache_size=0to the connection string so looks like a bug in the statement cache implementation. Add this to the connection string as a workaround for now.You need to enable mode using
DEBUG=*to see these error logs. I am marking this as confirmed bug.Relevant stack traces:
@lperrious @vladimiremi @danil-iglu @tminard @DimosthenisK @macrozone @MarcusHSmith @Jackman3005 @paustint To confirm something: Are you all using
enums in your Prisma Schema as @JackieJoo does?I am.
What seemed to fix it for me was adding
prismaClient.$disconnect()in the afterEach hook and reinstating the prismaClient in beforeEach.@pantharshit00 OMG thank you for your comment about the
&statement_cache_size=0workaround!I’ve been futsin around with trying to get end-to-end tests working in GitHub Actions for two days and been stuck on this issue and this has solved it for me 🙏
We’ve also seen this error here and there when we have the API running and do a
yarn prisma migrate reset. In our CI environment we were getting this error 100% of the time. I’m not sure what Prisma can do to fix this at runtime, but would love to see it resolved for good!In the off-chance I can help another poor wondering soul, here’s a bit of information on my situation.
Prisma Migration
We have a table called “FormPrototype” and it has a column that is an enum called “status”. We have quite a few prisma generated migration files now and one of them has the following:
Note: this was generated when we removed a status from the enum
Postgres Error
I believe that migration code in collaboration with how Postgres does caching is the cause for the following error that I was getting from the postgres container logs in my CI environment:
Prisma Error
End-to-end setup
We are using GitHub Actions and using the services feature specifying a Postgres container. Nothing too special here.
We have a
startbash script that does the following to prepare and start our API:I fixed the order. First query fails with
cached plan must not change result typewhich in turns fails another query because it received null instead of a valid id.