New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix FOR UPDATE OF with explicit schema #5791
base: master
Are you sure you want to change the base?
Conversation
When the _tableNames helper was written there were multiple methods hitting it, but they've since been merged into the single _lockingClause method. Given that the only really interesting thing it was doing was prepending the schema name--which is the incorrect behavior this commit fixes--it didn't seem worth keeping at this point. I'm not sure you'd say `.withSchema('public')` in a real query but it lets me exercise the behavior in question without having to learn enough about knex's test environment to stand up a discrete schema. I suppose it's plausible that a reasonable maintainer would go "hm that's silly and redundant" and inadvertently remove coverage for this bug, though.
@@ -197,29 +197,12 @@ class QueryCompiler_PG extends QueryCompiler { | |||
} | |||
} | |||
|
|||
// Join array of table names and apply default schema. | |||
_tableNames(tables) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When the _tableNames
helper was written (#2835) there were multiple methods hitting it, but they've since been merged into the single _lockingClause
method. Given that the only really interesting thing it was doing was prepending the schema name--which is the incorrect behavior this commit fixes--it didn't seem worth keeping at this point.
@@ -993,7 +993,7 @@ describe('Selects', function () { | |||
try { | |||
await knex.transaction((trx) => { | |||
// select all from two test tables and lock only one table | |||
return trx('test_default_table') | |||
return trx.withSchema('public').from('test_default_table') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure you'd say .withSchema('public')
in a real query but it lets me exercise the behavior in question without having to learn enough about knex's test environment to stand up a discrete schema 😁
Turns out your changes only show up in git if you press "save" in your editor. Who knew!
When calling
.withSchema(...)....forUpdate('someTable')
, knex would produce incorrect sql syntax—it included the schema name in the table name, prompting a "FOR UPDATE must specify unqualified relation names" error from postgresql.Fixes #5053.