Skip to content

parseRangeBound function fails #5747

Closed
Closed

Description

@nabil-brn

Set up a table with int4range attribute :

What you are doing?

module.exports = function(sequelize, DataTypes) {
    return sequelize.define('test', {
        id: {
            type: DataTypes.INTEGER,
            allowNull: false,
            primaryKey: true,
            autoIncrement: true
        },
        name: {
            type: DataTypes.TEXT,
            allowNull: false,
            unique: true
        },
        interval: {
            type: DataTypes.RANGE(DataTypes.INTEGER),
            allowNull: false,
            unique: true
        }
    }, {
        tableName: 'test'
    });
};
INSERT INTO test  (name, interval) VALUES ('test', '[1,4]');

Perform a findAll

var query = models.test.findAll({})

What do you expect to happen?

[{"id":1,"name":"test","interval":[[1],[5]]}]
-> 5 when incluse = false

What is actually happening?

[{"id":1,"name":"test","interval":[[],[]]}]
-> Bounds are empty

Debug

//lib/dialects/postgres/range.js
[...]
function parse (value, parser) {
  console.log("var parser: "+ parser)
  if (value === null) return null;
  if (value === 'empty') {
    var empty = [];
    empty.inclusive = [];
    return empty;
  }
​
  var result = value
    .substring(1, value.length - 1)
    .split(',', 2);
​
  console.log("Before parseRangeBound, result = "+ result)
​
  if (result.length !== 2) return value;
  result = result
    .map(function (value) {
      return parseRangeBound(value, parser);
    });
  console.log("After parseRangeBound, result = "+ result)
​
  result.inclusive = [(value[0] === '['), (value[value.length - 1] === ']')];
  return result;
}

Output :
Before parseRangeBound, result = 1,7
After parseRangeBound, result = ,

Dialect: postgres
Database version: 9.5
Sequelize version: 3.21.0

Activity

  1. added
    type: bug
    on Apr 14, 2016
  2. alitaheri commented on Jun 1, 2016

    @alitaheri
    Contributor

    Does this still fail?

  3. sushantdhiman commented on Jun 20, 2016

    @sushantdhiman
    Contributor

    Confirmed

    Using database:  sequelize-test-12
    Executing (default): INSERT INTO "test" ("id","name","interval","createdAt","updatedAt") VALUES (DEFAULT,'test','[1,5)','2016-06-20 07:55:13.127 +00:00','2016-06-20 07:55:13.127 +00:00') RETURNING *;
    Executing (default): SELECT "id", "name", "interval", "createdAt", "updatedAt" FROM "test" AS "test";
    [ { id: 1,
        name: 'test',
        interval: [ [], [], inclusive: [Object] ],
        createdAt: 2016-06-20T07:55:13.127Z,
        updatedAt: 2016-06-20T07:55:13.127Z } ]
    
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    type: bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions