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/geo null #1334

Merged
merged 10 commits into from
Apr 24, 2017
Merged

Fix/geo null #1334

merged 10 commits into from
Apr 24, 2017

Conversation

paulussup
Copy link
Contributor

@paulussup paulussup commented Apr 19, 2017

Description

Add check for null and undefined.

Related issues

#1332
connect to #1332

  • None

Checklist

  • New tests added or existing tests modified to cover all changes
  • Code conforms with the style
    guide

@slnode
Copy link

slnode commented Apr 19, 2017

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

@slnode
Copy link

slnode commented Apr 19, 2017

Can one of the admins verify this patch?

2 similar comments
@slnode
Copy link

slnode commented Apr 19, 2017

Can one of the admins verify this patch?

@slnode
Copy link

slnode commented Apr 19, 2017

Can one of the admins verify this patch?

@ebarault ebarault requested a review from ssh24 April 19, 2017 08:09
Copy link
Contributor

@ebarault ebarault left a comment

Choose a reason for hiding this comment

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

thanks for contributing this fix, please review the requested changes

lib/geo.js Outdated
@@ -24,7 +24,7 @@ exports.nearFilter = function nearFilter(where) {
var ret = nearSearch(el, parentKeys.concat(clauseKey).concat(index));
if (ret) return ret;
});
} else {
} else if (clause[clauseKey] !== null && clause[clauseKey] !== undefined) {
Copy link
Contributor

Choose a reason for hiding this comment

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

we usually prefer early return to keep the code simpler to read, i suggest:

Object.keys(clause).forEach(function(clauseKey) {
  if (typeof clause[clauseKey] !== 'object' || !clause[clauseKey]) return;

  if (Array.isArray(clause[clauseKey])) {
    // array
  // object different than null, undefined, 0
  } else {
    // object other than null, undefined, 0
  }
}

@@ -153,6 +153,27 @@ describe('basic-querying', function() {
done();
});
});
it('should query by ids and null condition', function(done) {
Copy link
Contributor

Choose a reason for hiding this comment

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

is it required for this test to search among these 4 users? unless i'm missing something could you simplify with only 2 different users?

Copy link
Contributor

@ebarault ebarault left a comment

Choose a reason for hiding this comment

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

LGTM: @ssh24 i let you check

createdUsers[1].id],
{where: {vip: null}}, function(err, users) {
should.exist(users);
should.not.exist(err);
Copy link
Contributor

Choose a reason for hiding this comment

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

@paulussup Could you please swap L161 with L162? It is always a good idea to check err first.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed @ssh24

@ssh24
Copy link
Contributor

ssh24 commented Apr 19, 2017

@slnode test please

2 similar comments
@ssh24
Copy link
Contributor

ssh24 commented Apr 19, 2017

@slnode test please

@ssh24
Copy link
Contributor

ssh24 commented Apr 19, 2017

@slnode test please

User.findByIds([
createdUsers[0].id,
createdUsers[1].id],
{where: {vip: null}}, function(err, users) {
Copy link
Contributor

Choose a reason for hiding this comment

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

@paulussup @ebarault I am not sure if this test case checks for the fix in the right away. The fix is however correct.

Shouldn't the filter do near query with a null value and see if the null value it is taken care of? Something like this test case but with a null value filter: 64f64ca#diff-8fae24fa21c82e23f7f43ccdae4fcf90R599

@paulussup
Copy link
Contributor Author

paulussup commented Apr 19, 2017 via email

@ssh24
Copy link
Contributor

ssh24 commented Apr 19, 2017

@paulussup That is fine. We can still keep this test case and just add that extra test case.

The test case is also failing on mongodb and cassandra connector so need to look into that.

@paulussup
Copy link
Contributor Author

paulussup commented Apr 19, 2017 via email

@ssh24 ssh24 self-assigned this Apr 19, 2017
@ssh24 ssh24 force-pushed the fix/geo_null branch 2 times, most recently from 64494dd to fa680d1 Compare April 19, 2017 15:50
@ssh24
Copy link
Contributor

ssh24 commented Apr 19, 2017

@slnode test please

@ssh24
Copy link
Contributor

ssh24 commented Apr 19, 2017

@ebarault This fix looks good to me. Could you do me a favour and review the changes I committed, i.e fixing and adding new test cases?

@slnode test please

Copy link
Contributor

@ssh24 ssh24 left a comment

Choose a reason for hiding this comment

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

Fix LGTM. Waiting on CI and @ebarault to review my test fixes.

@ssh24
Copy link
Contributor

ssh24 commented Apr 19, 2017

@slnode test please

Copy link
Contributor

@ebarault ebarault left a comment

Choose a reason for hiding this comment

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

@ssh24: i see your point.
My main concern is about test naming, please see my inlined comments

@@ -153,6 +153,26 @@ describe('basic-querying', function() {
done();
});
});
it('should query by ids and null condition', function(done) {
// due to some connectors not being assigning null value by default
// the query is filtered by the fields which may consist null value
Copy link
Contributor

Choose a reason for hiding this comment

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

typo: "which may consist in null value ..."

User.findByIds([
createdUsers[0].id,
createdUsers[1].id],
{fields: {name: true, vip: true}}, function(err, users) {
Copy link
Contributor

Choose a reason for hiding this comment

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

i'm afraid i don't understand, the test is named: 'should query by ids and null condition' and we are not querying by null value here. I suspect it should be vip: null here?

Copy link
Contributor

Choose a reason for hiding this comment

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

or i'm missing this: one of the user has an undefined property "vip" and the test should be named something like: 'should query by ids and condition, allowing results where conditions match null properties'

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have to say I don't see how this test is even testing the behaviour that caused this bug. The problem arose when traversing the where object for the near key and the value is {where: {field: null}}. Would it not make more sense to set vip explicitly to null in this test case or create new test seed data with explicit null values.

Copy link
Contributor

Choose a reason for hiding this comment

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

@paulussup Good question. Your test case was not wrong however it had a loophole where it would not check for connectors which does not put null values for fields which are not set (it would instead have it as undefined, for example mongodb).

Improved the test case to take care of that situation by filtering by fields (name and vip) and then get those instances back and then perform a check if they are either null or undefined. After fixing this it works with the downstream connectors such as mongodb and cassandra.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I accept that it fixes the downstream issue. If there was a test which actually set the value explicitly to null in the test I think this too would allow the downstream connectors to query the null value and return records. Mongo and Cassandra can both store null values.

Copy link
Contributor

Choose a reason for hiding this comment

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

@paulussup Yes I agree with you. Would you like to fix the test cases to go with the changes you proposed? We can just add a property vip with value null on the second user of createdUsers and just query that with your previous test case.

Please be sure to pull latest from your branch if you haven't already.

@@ -593,6 +613,19 @@ describe('basic-querying', function() {

describe('geo queries', function() {
describe('near filter', function() {
it('supports a near query with null condition', function(done) {
Copy link
Contributor

Choose a reason for hiding this comment

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

could you move this test right after the 'supports a basic "near" query' test please?

Copy link
Contributor

Choose a reason for hiding this comment

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

if i'm right in my previous comment the test name should also be revised to reflect that we are not querying on a null condition, but that results on the conditions could come with empty properties

something like:
'supports a compound near query with conditions, allowing results where conditions match null properties'

@ssh24
Copy link
Contributor

ssh24 commented Apr 19, 2017

@ebarault Updated the test messages.

@slnode test please

@paulussup
Copy link
Contributor Author

paulussup commented Apr 20, 2017 via email

@ssh24
Copy link
Contributor

ssh24 commented Apr 21, 2017

@paulussup Any updates on fixing the test cases?

@paulussup
Copy link
Contributor Author

paulussup commented Apr 21, 2017 via email

@ssh24
Copy link
Contributor

ssh24 commented Apr 22, 2017

@paulussup I have fixed the test cases myself.

@ssh24
Copy link
Contributor

ssh24 commented Apr 22, 2017

@slnode test please

@ssh24
Copy link
Contributor

ssh24 commented Apr 24, 2017

@slnode test please

2 similar comments
@ssh24
Copy link
Contributor

ssh24 commented Apr 24, 2017

@slnode test please

@ssh24
Copy link
Contributor

ssh24 commented Apr 24, 2017

@slnode test please

@ssh24
Copy link
Contributor

ssh24 commented Apr 24, 2017

PR ready to be landed. @paulussup Thank you again for the patch!

@ssh24 ssh24 merged commit e9ff88f into loopbackio:master Apr 24, 2017
@ssh24 ssh24 added the apex label Apr 24, 2017
@ssh24 ssh24 added this to the Sprint 34 - Apex milestone Apr 24, 2017
pastcompute added a commit to pastcompute/loopback-datasource-juggler that referenced this pull request Apr 25, 2017
kjdelisle pushed a commit that referenced this pull request May 2, 2017
 * create sequence for nosql id (#1354) (Janny)
 * Fix order of query results (Loay)
 * Add DateString type (Kevin Delisle)
 * datatype.test: use predefined date (Kevin Delisle)
 * Update api documents (Loay)
 * Datasource documentation tune-up (Kevin Delisle)
 * Added unit tests specific to DateType where null (#1349) (Andrew McDonnell)
 * Fix/geo null (#1334) (paulussup)
 * replace exception thrown for invalid dates (Diana Lau)
 * Revert PR #1326 (#1336) (Sakib Hasan)
 * Make lib peerDepend on loopback-connector (#1326) (Russ Tyndall)
 * Add test case using updateAttributes (Loay)
 * Fix forceId bug for updateOrCreate (Loay)
 * Fix typo in description (jannyHou)
 * Fix relations test case (loay)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants