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
fix(data-types): moment object throwing error #13818
Conversation
Can we add regression tests for this? So one inputting a JS Date and one with a Moment object to check that this works without errors? |
I think we should have a test that verifies that you can pass a moment instance. edit: ... what Rik said :D |
I have added a test case but it is blowing up since the code change does not seem to fix the problem |
@sdepold might be good to revert #13712 in the v6 branch for now since it was just a minor change to get rid of a deprecation warning (and with moment being deprecated itself not to worry that it will be removed). This second change looks too big to me and with timezone things you always need to be careful And then later we can see if @fncolon can find a better fix that works with different types of Date-related objects |
I agree |
I tried to find the blowing up parts, can you give me the specific result? |
Agree! 😃 |
Actually I'm confused now myself. Let me have a look. |
Local:
|
oh I forgot to build the project 👌 |
Alright. So, it works just fine locally (as in the tests are green). Should we merge the change or rather revert to the old solution. I'm fine with both really. Since this might be one of the last versions of sequelize 6 it might be worth fixing the warning. However, if we feel it's too unsafe, reverting is also ok. |
* fix(data-types): moment object throwing error * fix: typo * fix: revert with consistent variable naming * test(moment): add moment support test case Co-authored-by: Sascha Depold <sdepold@users.noreply.github.com> Co-authored-by: Sascha Depold <sascha@depold.com>
🎉 This PR is included in version 7.0.0-alpha.3 🎉 The release is available on: Your semantic-release bot 📦🚀 |
🎉 This PR is included in version 7.0.0-alpha2.1 🎉 The release is available on: Your semantic-release bot 📦🚀 |
So I noticed this change when reviewing #14400, and this PR + #13712 sound very strange to me. Why would we only apply the Isn't that a breaking change? Before this change, the With time zones it's very likely that this breaking change would have gone unnoticed. |
It is actually throwing error before this changes for some cases What I did was to follow the default of how we handle timezone and date and then I found out we can't applied to all dates if the filter was using momentjs, so that's why this error did happen. Before this change, the timezone option was applied to all dates indiscriminately of which library created the date was passing to momentjs function and returning some unexpected errors. (#13816). |
But I agree with you, this should be breaking change also we didn't applied all dates indiscrimantely correctly before, so we need much further changes to fix this issue #13816 without breaking changes, or accept the breaking change (since no one complain about if there's any usage turns out to be breaking) |
Because of #13712, or before that PR too? Because that PR introduced the breaking change too.
It's only been a couple of months since this was published and a subtle change like this would not cause an error to be thrown. You'd have to look at the data to realize something changed. Either way, I think both of these PRs should be reverted. If all they did was fixed the warning from moment, we should look into fixing the warning in a non-breaking way. |
before that PR too |
Do you have more info about the error that was being thrown prior to #13712? |
I don't have any but that's actually not correctly way of applyTimezone and one of the issue report is the one above |
I'm sorry I don't understand what you mean, what was incorrect with
A warning, not an error. So it must be resolved in a backward compatible way. The current fix that skips applyTimezone if it's already a moment object is not backward compatible as we end up with different values being stored: Do you remember in which scenarios moment logged that warning? |
It's incorrect because we use applyTimezone without filtering if it was moment compatible date or not so it will throwing a warning that might we didn't want to see and don't know how to hide it, but unfortunately like you said it is introducing breaking change (but I didn't see anyone notice if it was a breaking change). |
As I said, the warning should be fixed, but in a backward compatible way.
As I said earlier, it doesn't mean it did not introduce bugs that have gone unnoticed, which again is especially easy when it comes to time zones. Or that it won't introduce a bug for someone that has not updated to Sequelize > 6.12 (even if they already were on Sequelize 6), so this is really not a valid point. |
Indeed :), I was not minding for you to revert it, I will search up how to come up with a backward compatibility solution soon. |
I actually didn't input anything when the warning was thrown, it was thrown when I was getting data with the DATE type attribute. |
This is the workaround const crowdFundings = await CrowdFunding.findAndCountAll({
distinct: true, // don't count the include part https://github.com/sequelize/sequelize/pull/4016#issuecomment-116294996
attributes: [
'date_attributes' // <- will cause the warning from momentjs
],
include: [{ all: true }],
where: {
...data,
[Op.or]: searchUtil.search(crowdFundingAttributes, query.q || ""),
},
...pagination.getPaginationOptionsData(),
}); model.js date_attributes: {
type: DataTypes.DATE,
allowNull: false,
}, |
Thanks, I'll see if I can reproduce the error! |
@ephys did you reproduce it? Do we need to revert it in v6 or shall we just keep it this way until we get complaints? |
I haven't taken the time to reproduce the initial warning yet, but I did test the behavior before & after this change and it does produce different datetime strings. It produces the same UTC time, but using different UTC offsets, e.g. This may be an issue in itself for some applications. It requires the user to be using both moment and the timeZone option in the sequelize constructor, which is probably going to be a small percentage of users. |
Thanks for the research |
* fix(data-types): moment object throwing error * fix: typo * fix: revert with consistent variable naming * test(moment): add moment support test case Co-authored-by: Sascha Depold <sdepold@users.noreply.github.com> Co-authored-by: Sascha Depold <sascha@depold.com>
Pull Request Checklist
Please make sure to review and check all of these items:
npm run test
ornpm run test-DIALECT
pass with this change (including linting)?Description Of Change
Fix #13816 , wrong if else and replace date checking with isMoment.
Todos