-
Notifications
You must be signed in to change notification settings - Fork 365
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
Fix/geo null #1334
Conversation
Can one of the admins verify this patch? To accept patch and trigger a build add comment ".ok\W+to\W+test." |
Can one of the admins verify this patch? |
2 similar comments
Can one of the admins verify this patch? |
Can one of the admins verify this patch? |
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.
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) { |
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.
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
}
}
test/basic-querying.test.js
Outdated
@@ -153,6 +153,27 @@ describe('basic-querying', function() { | |||
done(); | |||
}); | |||
}); | |||
it('should query by ids and null condition', 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.
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?
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.
LGTM: @ssh24 i let you check
test/basic-querying.test.js
Outdated
createdUsers[1].id], | ||
{where: {vip: null}}, function(err, users) { | ||
should.exist(users); | ||
should.not.exist(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.
@paulussup Could you please swap L161 with L162? It is always a good idea to check err
first.
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.
fixed @ssh24
@slnode test please |
test/basic-querying.test.js
Outdated
User.findByIds([ | ||
createdUsers[0].id, | ||
createdUsers[1].id], | ||
{where: {vip: null}}, function(err, users) { |
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.
@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
To be honest I copy pasted the test above written by @raymondfeng and made the required edits. The reason that I chose to just test the null value is that the documentation uses querying a field as null as an example. Because this was not tested the error was able to make its way in to master.
… On 19 Apr 2017, at 10:40 pm, Sakib Hasan ***@***.***> wrote:
@ssh24 commented on this pull request.
In test/basic-querying.test.js <#1334 (comment)>:
> @@ -153,6 +153,18 @@ describe('basic-querying', function() {
done();
});
});
+ it('should query by ids and null condition', function(done) {
+ User.findByIds([
+ createdUsers[0].id,
+ createdUsers[1].id],
+ {where: {vip: null}}, function(err, users) {
@paulussup <https://github.com/paulussup> @ebarault <https://github.com/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 <64f64ca#diff-8fae24fa21c82e23f7f43ccdae4fcf90R599>
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub <#1334 (review)>, or mute the thread <https://github.com/notifications/unsubscribe-auth/AJCRmHAIRoYImdENLnkPD_ZQzsYZrDyhks5rxge2gaJpZM4NBJ0R>.
|
@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. |
I guess that is because those datasources don’t default the value to null when persisting like the sql datasources.
… On 19 Apr 2017, at 11:39 pm, Sakib Hasan ***@***.***> wrote:
@paulussup <https://github.com/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.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub <#1334 (comment)>, or mute the thread <https://github.com/notifications/unsubscribe-auth/AJCRmL9ipkuDFmBoWVoHdJboBVribxfFks5rxhWBgaJpZM4NBJ0R>.
|
64494dd
to
fa680d1
Compare
@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.
Fix LGTM. Waiting on CI and @ebarault to review my test fixes.
@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.
@ssh24: i see your point.
My main concern is about test naming, please see my inlined comments
test/basic-querying.test.js
Outdated
@@ -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 |
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: "which may consist in null value ..."
test/basic-querying.test.js
Outdated
User.findByIds([ | ||
createdUsers[0].id, | ||
createdUsers[1].id], | ||
{fields: {name: true, vip: true}}, function(err, users) { |
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 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?
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.
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'
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 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.
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.
@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.
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 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.
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.
@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.
test/basic-querying.test.js
Outdated
@@ -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) { |
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.
could you move this test right after the 'supports a basic "near" query' 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.
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'
Sure no problems.
… On 20 Apr 2017, at 9:00 pm, Sakib Hasan ***@***.***> wrote:
@ssh24 commented on this pull request.
In test/basic-querying.test.js <#1334 (comment)>:
> @@ -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
+ // or not exist at all
+ User.findByIds([
+ createdUsers[0].id,
+ createdUsers[1].id],
+ {fields: {name: true, vip: true}}, function(err, users) {
@paulussup <https://github.com/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.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub <#1334 (comment)>, or mute the thread <https://github.com/notifications/unsubscribe-auth/AJCRmBT3oH42krpyL0lEoYnNslZA8joHks5rx0HlgaJpZM4NBJ0R>.
|
@paulussup Any updates on fixing the test cases? |
Haven’t had a chance yet.
… On 22 Apr 2017, at 4:16 am, Sakib Hasan ***@***.***> wrote:
@paulussup <https://github.com/paulussup> Any updates on fixing the test cases?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub <#1334 (comment)>, or mute the thread <https://github.com/notifications/unsubscribe-auth/AJCRmPbFORPiy_rdnhQWsxCVI0b1_VxRks5ryPmMgaJpZM4NBJ0R>.
|
Some connectors uses a non existent prop instead of allowing null Modified test case to look if null exists or the prop is non existent
@paulussup I have fixed the test cases myself. |
@slnode test please |
@slnode test please |
PR ready to be landed. @paulussup Thank you again for the patch! |
* 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)
Description
Add check for null and undefined.
Related issues
#1332
connect to #1332
Checklist
guide