-
Notifications
You must be signed in to change notification settings - Fork 99
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 #161 - Wrong queries causes unhandled exceptions #162
Conversation
Can one of the admins verify this patch? To accept patch and trigger a build add comment ".ok\W+to\W+test." |
@slnode test please |
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.
You are on the right track, keep going 👏
@bajtos I have fixed all according to your comments, can you please review again? |
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.
Almost there! I have few minor/stylistic comments, the actual implementation & tests look good.
I'll am taking a longer break now, won't be able to follow up on this discussion until January. Can somebody from @strongloop/loopback-maintainers take over the review process of this pull request please?
} catch (err) { | ||
if (cb) { | ||
cb(err); | ||
} |
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.
Nitpick: let's shorten this block as follows:
if (cb) cb(err);
return;
Same comment applies to other similar places too.
const msg = g.f('Unknown property %s is used for model %s', key, model); | ||
const error = new Error(msg); | ||
error.statusCode = error.status = 400; | ||
error.code = 'UNKNWON_PROPERTY'; |
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.
Typo.
error.code = 'UNKNWON_PROPERTY'; | |
error.code = 'UNKNOWN_PROPERTY'; |
}); | ||
}); | ||
|
||
it('should ignore if invalid order by statement is used by all', function(done) { |
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.
If find it a bit difficult to spot why some tests are ignoring invalid statements while others are throwing an error. Can you please group the tests for "should ignore" using describe
block?
describe('with ignoreUnknownProperties: true', () => {
it('should ignore if invalid order by statement is used by all', function(done) {
// ...
});
// ...
});
@@ -270,6 +293,57 @@ describe('sql connector', function() { | |||
expect(orderBy).to.eql('ORDER BY `NAME` ASC,`VIP` DESC'); | |||
}); | |||
|
|||
it('builds order by with non existent field throws', function() { | |||
expect(() => { | |||
connector.buildOrderBy('customer', ['nam?e', 'name']); |
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 have mixed feeling about the value nam?e
, I believe it's not a valid property name in LoopBack. Can you please use a different property name, for example unknown
?
connector.buildOrderBy('customer', ['nam?e', 'name']); | |
connector.buildOrderBy('customer', ['unknown', 'name']); |
@slnode ok to test |
@bajtos I see that there are failing tests in downstream but I can't open the results to check why - the website is unreachable... |
Unfortunately, cis-jenkins is accessible only from inside IBM network :( Let me check the errors for you. Cassandra Click to expand the log1) cassandra custom tests find and order by str: AssertionError: expected Error { status: 400, statusCode: 400, code: 'UNKNWON_PROPERTY', message: 'Unknown property id is used for model CASS_SORTABLE' } to not exist at test/cass.custom.test.js:277:20 at allCb (node_modules/loopback-datasource-juggler/lib/dao.js:1740:7) at Cassandra.find [as all] (node_modules/loopback-connector/lib/sql.js:1521:12) at invokeConnectorMethod (node_modules/loopback-datasource-juggler/lib/dao.js:172:21) at node_modules/loopback-datasource-juggler/lib/dao.js:1755:7 at doNotify (node_modules/loopback-datasource-juggler/lib/observer.js:155:49) at doNotify (node_modules/loopback-datasource-juggler/lib/observer.js:155:49) at Function.ObserverMixin._notifyBaseObservers (node_modules/loopback-datasource-juggler/lib/observer.js:178:5) at Function.ObserverMixin.notifyObserversOf (node_modules/loopback-datasource-juggler/lib/observer.js:153:8) at Function.ObserverMixin._notifyBaseObservers (node_modules/loopback-datasource-juggler/lib/observer.js:176:15) at Function.ObserverMixin.notifyObserversOf (node_modules/loopback-datasource-juggler/lib/observer.js:153:8) at Function.find (node_modules/loopback-datasource-juggler/lib/dao.js:1753:10) at Context.<anonymous> (test/cass.custom.test.js:274:19) 2) cassandra custom tests find and order by num: AssertionError: expected Error { status: 400, statusCode: 400, code: 'UNKNWON_PROPERTY', message: 'Unknown property id is used for model CASS_SORTABLE' } to not exist at test/cass.custom.test.js:290:20 at allCb (node_modules/loopback-datasource-juggler/lib/dao.js:1740:7) at Cassandra.find [as all] (node_modules/loopback-connector/lib/sql.js:1521:12) at invokeConnectorMethod (node_modules/loopback-datasource-juggler/lib/dao.js:172:21) at node_modules/loopback-datasource-juggler/lib/dao.js:1755:7 at doNotify (node_modules/loopback-datasource-juggler/lib/observer.js:155:49) at doNotify (node_modules/loopback-datasource-juggler/lib/observer.js:155:49) at Function.ObserverMixin._notifyBaseObservers (node_modules/loopback-datasource-juggler/lib/observer.js:178:5) at Function.ObserverMixin.notifyObserversOf (node_modules/loopback-datasource-juggler/lib/observer.js:153:8) at Function.ObserverMixin._notifyBaseObservers (node_modules/loopback-datasource-juggler/lib/observer.js:176:15) at Function.ObserverMixin.notifyObserversOf (node_modules/loopback-datasource-juggler/lib/observer.js:153:8) at Function.find (node_modules/loopback-datasource-juggler/lib/dao.js:1753:10) at Context.<anonymous> (test/cass.custom.test.js:287:19) The previous CI build passed and the error message is mentioning your newly introduced error code, therefore I am inclined to think that this is a legitimate problem. Maybe the Cassandra test suite is making an invalid call and we need to fix those two tests first? DashDB Click to expand the log> Cleaning up existing schemas ... This is not related to your changes. Let's see if the problem goes away in the next re-run. PostgreSQL Click to expand the log1) postgresql connector json data type allows ordering by nested json properties: Error: Unknown property address.city is used for model Customer at errorPropertyNotFound (node_modules/loopback-connector/lib/sql.js:1004:17) at PostgreSQL.SQLConnector.buildOrderBy (node_modules/loopback-connector/lib/sql.js:1269:13) at PostgreSQL.SQLConnector.buildSelect (node_modules/loopback-connector/lib/sql.js:1464:29) at PostgreSQL.find [as all] (node_modules/loopback-connector/lib/sql.js:1519:17) at invokeConnectorMethod (node_modules/loopback-datasource-juggler/lib/dao.js:172:21) at /home/jenkins/workspace/ds/loopback-connector-postgresql~master/node_modules/loopback-datasource-juggler/lib/dao.js:1730:7 at doNotify (node_modules/loopback-datasource-juggler/lib/observer.js:157:49) at doNotify (node_modules/loopback-datasource-juggler/lib/observer.js:157:49) at Function.ObserverMixin._notifyBaseObservers (node_modules/loopback-datasource-juggler/lib/observer.js:180:5) at Function.ObserverMixin.notifyObserversOf (node_modules/loopback-datasource-juggler/lib/observer.js:155:8) at Function.ObserverMixin._notifyBaseObservers (node_modules/loopback-datasource-juggler/lib/observer.js:178:15) at Function.ObserverMixin.notifyObserversOf (node_modules/loopback-datasource-juggler/lib/observer.js:155:8) at Function.find (node_modules/loopback-datasource-juggler/lib/dao.js:1728:10) at Context.<anonymous> (test/postgresql.test.js:745:16) This problem looks legitimate to me too. I think your code is not taking into account queries for nested properties? |
Please don't use |
@bajtos thanks will do, I will try to fix everything when I can |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
This issue has been closed due to continued inactivity. Thank you for your understanding. If you believe this to be in error, please contact one of the code owners, listed in the |
Fixes #161 and consolidates #132 and #125
Checklist
👉 Read and sign the CLA (Contributor License Agreement) 👈
npm test
passes on your machine