Skip to content

Postgres range inclusive property lost in JSON format #8471

Closed

Description

@kingjerod

What are you doing?

Querying a Postgres table with a daterange column and returning it as JSON.

const Timeline = Sequelize.define({
   id: {type: Sequelize.INTEGER, primaryKey: true},
   date_range: {type: Sequelize.RANGE(Sequelize.DATEONLY)}
});
const range = [
   {value: new Date(Date.UTC(2017, 0, 1)), inclusive: true},
   {value: new Date(Date.UTC(2017, 6, 1)), inclusive: false},
];
await Timeline.create({id: 1, date_range: range});
const row = await Timeline.findById(1);
console.log(JSON.stringify(row)); // No inclusive property

What do you expect to happen?

When returning the data as JSON, the inclusive data should not be lost.

In the docs, there is this optional format for updating, this would be better because it can be turned into JSON without losing any information:

const range = [
  { value: '2017-01-01', inclusive: false },
  { value: '2017-07-01', inclusive: true },
];

What is actually happening?

The inclusive property is lost. This is because the inclusive property is set on an array, and array properties are not converted into JSON (like Array.length).

{id:1, date_range: ['2017-01-01', '2017-07-01']}

Dialect: postgres
Dialect version: 9.6
Database version: 9.6
Sequelize version: 4.4.3
Tested with master branch: Yes

Activity

  1. stale commented on Jan 11, 2018

    @stale

    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 🙂

  2. added
    type: bug
    on Mar 24, 2018
  3. added this to the v5 milestone on Mar 24, 2018
  4. sushantdhiman commented on May 7, 2018

    @sushantdhiman
    Contributor

    Fixed by #9364

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

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions