-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
fix(sum): returns 0 when is empty matching #9984
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
Conversation
Codecov Report
@@ Coverage Diff @@
## master #9984 +/- ##
==========================================
+ Coverage 96.38% 96.39% +<.01%
==========================================
Files 63 63
Lines 9389 9395 +6
==========================================
+ Hits 9050 9056 +6
Misses 339 339
Continue to review full report at Codecov.
|
|
@sushantdhiman Could you take a look at this fix too? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sum should return 0 not null as number is expected for this method. It should be solved at Model.aggregate level rather than query-interface level.
|
I changed to return 0. |
|
|
||
| if (dataType instanceof DataTypes.DECIMAL || dataType instanceof DataTypes.FLOAT) { | ||
| result = parseFloat(result); | ||
| if (!_.isNull(result)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I kept this change to not return NaN
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
|
Thanks @t-bonatti
Correct behaviour if we want to know if record exists as per our condition, but I can't say other dialect adheres to this. We can simply return numerical values from |
|
Is this already on 4.42.0? |
|
I am just upgrading to Sequelize 5, and this caught me by surprise. It seems very strange that this method now returns 0 if the result is null. This seems to assume that the result of an aggregation is a number. This is not at all the case in general. It can really be any datatype, and by returning 0 as a default, this breaks the expected type. In our case we are using it to find the max of a date field. |

Pull Request check-list
Please make sure to review and check all of these items:
npm run testornpm run test-DIALECTpass with this change (including linting)?Description of change
Fix #6299