fix(drizzle): sort by join field on versioned collection with custom text id#16391
Open
nathanbowang wants to merge 2 commits intopayloadcms:mainfrom
Open
Conversation
…text id When the list view is sorted by a `join` field on a collection that has both `versions` enabled and a custom text id (e.g. nanoid), the query crashes with: operator does not exist: integer = character varying `getTableColumnFromPath` builds the join condition using the versions table's `id` column. On a versions table, `id` is the versions row PK (always integer), not the parent document id. The joined `_rels` / target table column references the parent document id, which is `varchar` for custom text ids, so the types do not match. Use the versions table's `parent` column (mapped from the `parent_id` db column, which is the actual reference to the parent document id) instead of `id` whenever the source table is a versions table. Fixes both branches of `case 'join'` (single-segment `on` with `hasMany`, and the non-`hasMany` path). Made-with: Cursor
… text id Adds a regression test that creates a versioned collection with a custom text id and `join` fields (covering both the hasMany and non-hasMany branches in `getTableColumnFromPath`), then runs `payload.find` with `draft: true` and `sort` set to the join field. Without the fix this fails with: operator does not exist: character varying = integer Made-with: Cursor
177a48b to
0407620
Compare
Contributor
Author
|
The 3 failing checks all look unrelated to this PR (which only touches
Could a maintainer please rerun the failed jobs? I don't have permissions to do so on this fork. Happy to push an empty commit to retrigger if preferred. |
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?
Fix a Postgres crash when sorting the admin list view by a
joinfield on a collection that has bothversions: { drafts: true }enabled and a custom text id (e.g. nanoid).Why?
In that combination the query fails with
operator does not exist: integer = character varying, the broken sort is persisted intopayload_preferences, and the user cannot recover from the admin UI — the only fix today is to manually edit the database.How?
In
getTableColumnFromPath.ts, both branches ofcase 'join'built the join condition offadapter.tables[*].id. On a versions table (*_v)idis the version-row PK (integer), not the parent document id — but the joined column actually references the parent document id, which isvarcharfor custom text ids.Use the versions table's
parentcolumn (mapped fromparent_id) as the join key whenever the source table is a versions table. Both branches need the same fix; otherwise only some shapes ofonare repaired.Regression test added under
test/joins, exercising both code paths.Fixes #16390
Made with Cursor