Repository navigation
fix: return 404 for version operations when versions are disabled - #18057
Merged
jacobsfletch merged 4 commits intoOct 8, 2026
Merged
Conversation
jacobsfletch
requested changes
Oct 8, 2026
Member
There was a problem hiding this comment.
Thanks for taking a look at this @apoorvdarshan! Same comment as here: #18618 (review). We need to apply the same to collections as well, and call it sooner.
Edit: I went ahead and made these changes in ba07af5
…lections and check before access
…al-versions-3x # Conflicts: # test/versions/config.ts # test/versions/int.spec.ts # test/versions/slugs.ts
jacobsfletch
enabled auto-merge (squash)
October 8, 2026 14:45
jacobsfletch
approved these changes
Oct 8, 2026
jacobsfletch
added a commit
that referenced
this pull request
Oct 8, 2026
…8618) ### What? `GET /api/globals/<slug>/versions` (and `/versions/:id`) on a global with **versions disabled** returns HTTP 500 with `TypeError: Cannot read properties of undefined (reading 'id')` from the drizzle adapter. This PR makes it return a clean **404 Not Found**. This targets `main`. The open PR #18057 covers `3.x`. The bug matters more on `main`, because the website template ships `versions: false` globals (Header/Footer) while globals default to versioned. ### Why? `findVersionsOperation` and `findVersionByIDOperation` call `payload.db.findGlobalVersions` without checking `globalConfig.versions`. A global without versions has no versions table, so the drizzle adapter resolves `tableName` to `undefined` and crashes in `findMany`. Any authenticated user with `readVersions` access could trigger a 500 on a documented REST route. ### How? After the access check, both operations now throw `NotFound` when `globalConfig.versions` is falsy: ```ts if (!globalConfig.versions) { throw new NotFound(req.t) } ``` `findVersionByID` returns `null` instead when `disableErrors` is set, which matches how it already handles a missing version. The check runs after access, so an unauthenticated caller still gets 403 first and the response does not reveal anything new. 404 matches how the other "this resource doesn't exist" cases behave in the global version operations (`findVersionByID`, `restoreVersion`). **Tests:** I added a non-versioned global (`versions: false`) to `test/versions` and four int tests under "Globals - versions disabled": - Local API `findGlobalVersions` / `findGlobalVersionByID` throw `NotFound` - REST `GET /globals/<slug>/versions` and `/versions/1` return 404 Before the fix, all four failed with the TypeError from the issue (SQLite/drizzle). After the fix they pass, and the rest of `test/versions/int.spec.ts` passes. Fixes #18056 --------- Co-authored-by: Jake Fletcher <jacobsfletch@gmail.com>
Contributor
|
🚀 This is included in version v3.91.0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What?
Return an HTTP 400 response when global versions are requested for a global that does not have versions enabled.
Why?
The operation currently reaches the database adapter even though no versions table or model exists. SQL adapters can dereference a missing versions table, while MongoDB reports a missing model; both failures surface as an internal server error instead of explaining that the endpoint is unavailable for this global.
How?
readVersionsaccess check.Fixes #18056
Testing
pnpm run test:int globals— 14 passedpnpm run build:payload— successful