fix(drizzle): use table alias when sorting joined drafts by a localized field#17043
Open
yashs33244 wants to merge 2 commits into
Open
fix(drizzle): use table alias when sorting joined drafts by a localized field#17043yashs33244 wants to merge 2 commits into
yashs33244 wants to merge 2 commits into
Conversation
The bug is a Postgres FROM-clause error; it can't occur on MongoDB, and seeding a fresh versions collection inside a txn there is racy.
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?
Fixes invalid SQL (
invalid reference to FROM-clause entry for table "_r_v") when querying a collection that joins a localized draft collection whose default sort is a localized field (for example_statuswhenlocalizeStatusis on), with a locale set. Postgres-specific.Why?
buildOrderByruns against the join subquery's aliased version table, but it calledgetTableColumnFromPathwithout passingaliasTable. Thewherebuilder (parseParams) already passes it. For a localized sort column,getTableColumnFromPathbuilds the locales JOIN condition from(aliasTable || adapter.tables[tableName]).id; withaliasTableomitted it referenced the canonical, un-aliased version table, which isn't in the subquery's FROM clause - so Postgres rejected the query.How?
Pass
aliasTableinto thegetTableColumnFromPathcall inbuildOrderBy, matchingparseParams. The locales JOIN now references the aliased version table that's actually in scope.Added an integration test in the
localizeStatussuite (a join onto a draft collection sorted by_status) that fails on Postgres before the change and passes after.Fixes #15248