-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Error on empty result from table definition queries #1686
Error on empty result from table definition queries #1686
Conversation
@@ -328,7 +328,16 @@ module.exports = (function() { | |||
sql = 'DESCRIBE ' + table + ';' | |||
} | |||
|
|||
return this.sequelize.query(sql, null, { raw: true }) | |||
this.sequelize.query(sql, null, { raw: true }).then(function(data) { |
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.
Still need the return afaik
Good catch, crap. Fixed. |
Could throw I guess, just wanted it to act like the original query which simply rejects the promise with the error message from the server when something goes wrong, for example if you provide an invalid table name to the MySql DESCRIBE. |
Looks like this has exposed some bugs with schema handling in sqlite. Unfortunately, I'm not familiar enough with sqlite to be able to diagnose this. |
Throwing inside a promise is the same as rejecting it basically, it was just to reduce amount of code. |
@joshperry The error seems to be in the describeTableQuery fn of the sqlite query generator. When using tables with schema, it generates PRAGMA TABLE_INFO('`schema.table`') The table is both quoted and wrapped as a string. describeTableQuery: function(tableName, schema, schemaDelimiter) {
if (schema) {
schemaDelimiter = schemaDelimiter || '.'
tableName = schema + schemaDelimiter + tableName
}
var sql = "PRAGMA TABLE_INFO('<%= tableName %>');"
return Utils._.template(sql, { tableName: tableName})
}, Changing the function to the above should fix it :) |
@janmeier Thank you for the heads-up. It looks like the parameters to the |
Cool, whatever works. Could you add a couple of tests while you're at it |
@joshperry @janmeier status on this? |
Code looks good, but hoping for @joshperry to add a couple of tests before we merge :) |
What kind of tests would you like to see? If I have to be honest, the sqlite codebase looks pretty rough -- especially the schema support -- and, like I mentioned, I don't really have the time or means to work on this dialect. I fixed this bug because fixing the "error on no table definition" exposed the fact that it existed and I'd like to have this feature integrated with the existing tests passing. The test suite is in bad need of a refactor, it is difficult to follow and to upkeep because of the circuitous flow and disjoint hierarchy caused by logical blocks depending on the name of the dialect throughout. I'm using the Postgres dialect, and I would guess that as my project progresses that I will have more PRs come up there. |
A test covering what you changed. I.e. a proper error when the table doesn't exist. I don't see how the test suite is in bad need of a refactor, but people are of course entitled to their opinions :) We welcome most PRs, however the intent is for Sequelize to support all dialects equally (although with extra support for stuff like json for PG). |
Error on empty result from table definition queries
See the comments. Basically any query generator that relies on information_schema will just return an empty result if the table and/or schema are spelled incorrectly, or with the wrong case. Sequelize would just error out with a confusing error further up the stack when a function like
renameColumn
attempted to enumerate an empty table definition.It would be nice to backport this to 1.7 also.