Skip to content

Infinite range bounds are not handled correctly #8192

Closed

Description

@yazshel

What you are doing?

I'm wanting to filter a table on a Sequelize.Range(Sequelize.Date) with an infinite bound, but it appears that the SQL generator tries to convert the "null" range bound to a date, prior to building the range literal.

const Sequelize = require('sequelize');

const sequelize = new Sequelize('testdb', '', '', { dialect: 'postgres' });

class Test extends Sequelize.Model { }
Test.init({
  range: Sequelize.DataTypes.RANGE(Sequelize.DataTypes.DATEONLY),
}, { sequelize });

Test.findAll({ where: { range: { $overlap: [new Date(), null] } } })
    .then(() => console.log('Done'));

What do you expect to happen?

The infinte

SELECT "id", "range", "createdAt", "updatedAt" FROM "Tests" AS "Test" WHERE "Test"."range" && '["2017-08-25",)';

What is actually happening?

A quick look at RANGE.prototype._stringify() in lib/dialects/postgres/data-types.js the null range bound is incorrectly passed to the subtype stringify() function BEFORE it's been checked for null or Infinity/-Infinity. For Sequelize.RANGE(Sequelize.DATE) ranges, this results in the null range bound being stringified to "Invalid Date", which ends up being used in the range literal in the generated SQL:

SELECT "id", "range", "createdAt", "updatedAt" FROM "Tests" AS "Test" WHERE "Test"."range" && '["2017-08-25","Invalid date")';

Dialect: postgres
Database version: 9.6.4
Sequelize version: 4.7.2

Activity

  1. added
    type: bug
    on Aug 25, 2017
  2. added 2 commits that reference this issue on Aug 27, 2017
    0079130
    482e30a
  3. added a commit that references this issue on Aug 29, 2017
    5d2ba05
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