Skip to content
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

Deprecation warning: moment construction falls back to js Date #6483

Closed
callumlocke opened this issue Aug 22, 2016 · 7 comments
Closed

Deprecation warning: moment construction falls back to js Date #6483

callumlocke opened this issue Aug 22, 2016 · 7 comments
Labels

Comments

@callumlocke
Copy link

The same issue was opened and closed last year in #4954.

But I'm getting it today with the latest stable version of Sequelize, 3.24.1.

Deprecation warning: moment construction falls back to js Date. This is discouraged and will be removed in upcoming major release. Please refer to http://momentjs.com/guides/#/warnings/js-date/ for more info.
Arguments: [object Object]
Error
    at Function.createFromInputFallback (/code/foo/node_modules/moment/moment.js:285:105)
    at configFromString (/code/foo/node_modules/moment/moment.js:2015:32)
    at configFromInput (/code/foo/node_modules/moment/moment.js:2375:13)
    at prepareConfig (/code/foo/node_modules/moment/moment.js:2358:13)
    at createFromConfig (/code/foo/node_modules/moment/moment.js:2325:44)
    at createLocalOrUTC (/code/foo/node_modules/moment/moment.js:2412:16)
    at local__createLocal (/code/foo/node_modules/moment/moment.js:2416:16)
    at utils_hooks__hooks (/code/foo/node_modules/moment/moment.js:16:29)
    at DATE.$applyTimezone (/code/foo/node_modules/sequelize/lib/data-types.js:473:14)
    at DATE.$stringify (/code/foo/node_modules/sequelize/lib/data-types.js:483:15)
    at ABSTRACT.stringify (/code/foo/node_modules/sequelize/lib/data-types.js:77:17)
    at Object.QueryGenerator.escape (/code/foo/node_modules/sequelize/lib/dialects/abstract/query-generator.js:966:32)
    at Object.QueryGenerator.whereItemQuery (/code/foo/node_modules/sequelize/lib/dialects/abstract/query-generator.js:2272:22)
    at /code/foo/node_modules/sequelize/lib/dialects/abstract/query-generator.js:2167:28
    at /code/foo/node_modules/sequelize/node_modules/lodash/lodash.js:4389:15
    at baseForOwn (/code/foo/node_modules/sequelize/node_modules/lodash/lodash.js:2652:24)
@janmeier
Copy link
Member

What are you doing to make the issue appear?

@callumlocke
Copy link
Author

It's very hard to know, because the stack trace doesn't go back to my own code. All I know is it appears a lot in my logs.

But it's clear it's coming from this line in Sequelize, which is apparently relying on deprecated behaviour in Moment.js.

As far as I can tell, the date variable is a string in an unknown format, and Moment handles this by doing new Date(date) and printing a warning in the console. The best solution would be to track down why that variable is in the wrong format and fix it, assuming it's coming from somewhere inside Sequelize. Or, if the problem is that the badly formatted date string is coming from user code, then I would say Sequelize should probably check for this and reject the badly formatted date rather than trying to use it.

Background is here.

@felixfbecker
Copy link
Contributor

It can be fixed by providing the format of the date string. I don't know if that is the same across all database dialects and versions...

@redcomethk
Copy link

I also have the same problem.
Date string: "2015-09-08 08:01:08.678336"
Date Type: DataTypes.DATE
Dialect: 'postgres'
sequelize version: 3.24.1

@patrickocoffeyo
Copy link

I'm also experiencing this due to my use of Sequelize.DATE in a model. (Sequelize v3.24.1)

I'll look into it and create a PR when I figure out what's wrong.

@patrickocoffeyo
Copy link

@callumlocke After looking into this, this warning (documented here) basically states that you cannot pass just any string resembling a date into moment, instead the string must be a valid iso string with a timezone.

My issue was caused due a model that had a Sequelize.DATE property, but I was submitting an incorrectly formatted date (in my case, no value for the property.) This caused the code on this line to throw the error from moment.

@stale
Copy link

stale bot commented Jun 29, 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 🙂

@stale stale bot closed this as completed Jul 6, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants