Skip to content
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

Closed
wants to merge 8 commits into from

Conversation

regevbr
Copy link

@regevbr regevbr commented Nov 20, 2019

Fixes #161 and consolidates #132 and #125

Checklist

👉 Read and sign the CLA (Contributor License Agreement) 👈

  • npm test passes on your machine
  • New tests added or existing tests modified to cover all changes
  • Code conforms with the style guide
  • Commit messages are following our guidelines

@slnode
Copy link

slnode commented Nov 20, 2019

Can one of the admins verify this patch? To accept patch and trigger a build add comment ".ok\W+to\W+test."

@regevbr
Copy link
Author

regevbr commented Nov 21, 2019

@jannyHou @dhmlau can you please review the PR?

@dhmlau dhmlau added the community-contribution Patches contributed by community label Nov 25, 2019
@dhmlau
Copy link
Member

dhmlau commented Nov 26, 2019

@slnode test please

lib/sql.js Outdated Show resolved Hide resolved
@regevbr
Copy link
Author

regevbr commented Nov 26, 2019

@bajtos @dhmlau I have revied the changes proposed in #125 and #132 and add unit tests.
This should fix cover to cover hanging queries and faulty fields usage. Please let me know what you think

Copy link
Member

@bajtos bajtos left a 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 👏

lib/sql.js Outdated Show resolved Hide resolved
lib/sql.js Outdated Show resolved Hide resolved
lib/sql.js Outdated Show resolved Hide resolved
test/sql.test.js Outdated Show resolved Hide resolved
@regevbr
Copy link
Author

regevbr commented Nov 29, 2019

@bajtos I have fixed all according to your comments, can you please review again?

Copy link
Member

@bajtos bajtos left a 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);
}
Copy link
Member

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';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo.

Suggested change
error.code = 'UNKNWON_PROPERTY';
error.code = 'UNKNOWN_PROPERTY';

});
});

it('should ignore if invalid order by statement is used by all', function(done) {
Copy link
Member

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']);
Copy link
Member

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?

Suggested change
connector.buildOrderBy('customer', ['nam?e', 'name']);
connector.buildOrderBy('customer', ['unknown', 'name']);

@bajtos
Copy link
Member

bajtos commented Dec 13, 2019

@slnode ok to test

@bajtos bajtos requested a review from a team December 13, 2019 16:15
@regevbr
Copy link
Author

regevbr commented Dec 23, 2019

@bajtos I see that there are failing tests in downstream but I can't open the results to check why - the website is unreachable...

@bajtos
Copy link
Member

bajtos commented Jan 7, 2020

@regevbr

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 log
  1) 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 ...

/home/jenkins/workspace/ds/loopback-connector-dashdb~master/pretest.js:58
if (err) throw err;
^
Error: [IBM][CLI Driver] SQL30081N A communication error has been detected. Communication protocol being used: "TCP/IP". Communication API being used: "SOCKETS". Location where the error was detected: "9.30.198.63". Communication function detecting the error: "selectForConnectTimeout". Protocol specific error code(s): "115", "", "". SQLSTATE=08001

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 log
  1) 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?

@bajtos
Copy link
Member

bajtos commented Jan 7, 2020

Merge branch 'master' into #161

Please don't use git merge master and use git rebase master instead. We are keeping our git history linear.

@bajtos bajtos self-assigned this Jan 7, 2020
@regevbr
Copy link
Author

regevbr commented Jan 7, 2020

@bajtos thanks will do, I will try to fix everything when I can

@stale
Copy link

stale bot commented Mar 7, 2020

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.

@stale stale bot added the stale label Mar 7, 2020
@stale
Copy link

stale bot commented Mar 21, 2020

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 CODEOWNERS file at the top-level of this repository.

@stale stale bot closed this Mar 21, 2020
@lcsdms
Copy link

lcsdms commented May 5, 2021

Hey @bajtos and @regevbr , I've came from #125 with the same problem.

As I understand there's a need to fix those problems on the last tests right ? Is this the place to start if I'm contributing ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
community-contribution Patches contributed by community stale
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Wrong queries causes unhandled exceptions
5 participants