You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If this is still an issue, just leave a comment 🙂
In my case I'm querying against a date range (tstzrange in Postgres). Regardless of how I set the inclusivity the query that is generated is always '[)'.
range.inclusive = true;, range.inclusive = [true, true]; and range = [ { value: fromDate, inclusive: true}, { value: toDate, inclusive: true }]; all result in a query that is '[)' instead of '[]'.
The problem is that _.cloneDeepWith() doesn't copy properties on an array object.
I can get it to work by adding special handling to the cloneDeep() function in 'lib/utils.js' as follows...
function cloneDeep(obj) {
obj = obj || {};
return _.cloneDeepWith(obj, elem => {
// Special handling for the inclusive array property (for range types)
if (Array.isArray(elem) && elem.hasOwnProperty('inclusive')) {
var arr = _.map(elem, item => cloneDeep(item));
arr.inclusive = cloneDeep(elem.inclusive);
return arr;
}
// Do not try to customize cloning of arrays or POJOs
if (Array.isArray(elem) || _.isPlainObject(elem)) {
return undefined;
}
...
...
This resolves the problem when using either range.inclusive = true; or range.inclusive = [true,true];.
In the case where you define the range as range = [ { value: fromDate, inclusive: true}, { value: toDate, inclusive: true }]; the range is getting converted back to a simple [ fromDate, toDate ] somewhere by the time the stringify() function is called in 'lib/dialects/postgres/range.js'.
Further to this, I believe the problem with inclusivity being lost when using a single expression is in the RANGE.prototype._stringify() method in 'lib/dialects/postgres/data-types.js'. The map of the values in the range doesn't take this approach into account.
The modified version of the function below resolves that issue...
RANGE.prototype._stringify = function _stringify(values, options) {
if (!Array.isArray(values)) {
return "'" + this.options.subtype.stringify(values, options) + "'::" +
this.toCastType();
}
var valueInclusivity = [
_.isArray(values.inclusive) ? values.inclusive[0] : values.inclusive === false ? false : true,
_.isArray(values.inclusive) ? values.inclusive[1] : values.inclusive === true ? true : false
];
const valuesStringified = values.map((value, index) => {
if (value.hasOwnProperty('inclusive')) {
valueInclusivity[index] = value.inclusive;
}
if (value.hasOwnProperty('value')) {
value = value.value;
}
if (_.includes([null, -Infinity, Infinity], value)) {
// Pass through "unbounded" bounds unchanged
return value;
} else if (this.options.subtype.stringify) {
return this.options.subtype.stringify(value, options);
} else {
return options.escape(value);
}
});
// Array.map does not preserve extra array properties
valuesStringified.inclusive = valueInclusivity;
return '\'' + range.stringify(valuesStringified) + '\'';
};
But it use non standard array properties and likely will not pass our full test suite, I advice you to use proper fix from v5-beta once you get chance. Otherwise you may keep using your fix for your projects
Activity
sushantdhiman commentedon Aug 29, 2017
May be fixed #8210
skilFullGH commentedon Aug 31, 2017
Checked, the problem remained
stale commentedon Dec 9, 2017
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If this is still an issue, just leave a comment 🙂
mjy78 commentedon Mar 15, 2018
I believe this problem still persists.
Database Version: postgres 9.6.8
Sequelize Version: 4.26.1
In my case I'm querying against a date range (tstzrange in Postgres). Regardless of how I set the inclusivity the query that is generated is always '[)'.
range.inclusive = true;,range.inclusive = [true, true];andrange = [ { value: fromDate, inclusive: true}, { value: toDate, inclusive: true }];all result in a query that is '[)' instead of '[]'.sushantdhiman commentedon Mar 15, 2018
Can you try with latest version
mjy78 commentedon Mar 15, 2018
Still the same result with 4.37.0 (I had a typo in the version above - I was actually running on 4.36.1).
mjy78 commentedon Mar 15, 2018
The problem is that _.cloneDeepWith() doesn't copy properties on an array object.
I can get it to work by adding special handling to the cloneDeep() function in 'lib/utils.js' as follows...
This resolves the problem when using either
range.inclusive = true;orrange.inclusive = [true,true];.Please note however that the documented alternative of using a single expression still doesn't work with this fix in place.
In the case where you define the range as
range = [ { value: fromDate, inclusive: true}, { value: toDate, inclusive: true }];the range is getting converted back to a simple[ fromDate, toDate ]somewhere by the time the stringify() function is called in 'lib/dialects/postgres/range.js'.mjy78 commentedon Mar 15, 2018
Further to this, I believe the problem with inclusivity being lost when using a single expression is in the RANGE.prototype._stringify() method in 'lib/dialects/postgres/data-types.js'. The map of the values in the range doesn't take this approach into account.
The modified version of the function below resolves that issue...
fix(range-bounds): changed how range values are returned
fix(range-bounds): changed how range values are returned
theRichu commentedon Sep 14, 2018
I think this is should be re-open
Tutorial says,
but It is not working
and this is my fix
sushantdhiman commentedon Sep 14, 2018
@theRichu Which version?
theRichu commentedon Sep 14, 2018
sushantdhiman commentedon Sep 14, 2018
This is available on
v5-betaas this was a breaking changetheRichu commentedon Sep 14, 2018
Yeah,
I agree
this form is more clear
but my code not cause breaking change, and resolve the bug
sushantdhiman commentedon Sep 14, 2018
But it use non standard array properties and likely will not pass our full test suite, I advice you to use proper fix from v5-beta once you get chance. Otherwise you may keep using your fix for your projects
theRichu commentedon Sep 14, 2018
Ok, i'll check and test with v5-beta. Thanks