Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/fix-access-control-silent-error.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@keystone-6/core": patch
---

Fixed an issue where database errors (connection issues, timeouts, etc.) occurring during unique item existence checks (e.g. in relationship resolvers) were silently swallowed and replaced with a generic "Access denied" error. Unexpected errors are now correctly rethrown to aid debugging.
11 changes: 10 additions & 1 deletion packages/core/src/lib/core/access-control.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import type {
ListFilterAccessControl,
ListOperationAccessControl,
UpdateListItemAccessControl,
DeleteListItemAccessControl,
} from '../../types'
import { coerceAndValidateForGraphQLInput } from '../coerceAndValidateForGraphQLInput'
import { accessDeniedError, accessReturnError, extensionError, formatKeys } from './graphql-errors'
Expand Down Expand Up @@ -428,7 +429,15 @@ export async function checkUniqueItemExists(
try {
const item = await context.db[foreignList.listKey].findOne({ where: uniqueInput })
if (item !== null) return uniqueWhere
} catch (err) {}
} catch (err: any) {
// If it's an access denied error from context.db, we swallow it and throw our own
// to keep the error message consistent with "item may not exist".
// But if it's a real database error (e.g. connection, timeout, malformed query),
// we MUST rethrow it so the developer knows what happened.
if (err?.extensions?.code !== 'KS_ACCESS_DENIED') {
throw err
}
}

throw accessDeniedError(cannotForItem(operation, foreignList))
}