Skip to content

WIP: Mysql: Fix Model.count returning NaN. Closes #3019 - #3740

Closed
BridgeAR wants to merge 3 commits into
sequelize:masterfrom
fintura:return-nan
Closed

BridgeAR wants to merge 3 commits into
sequelize:masterfrom
fintura:return-nan

Conversation

@BridgeAR

Copy link
Copy Markdown
Contributor

This will fix DOUBLE and REAL being returned as numbers instead of strings. This will also fix the issue with iojs 2.0 and the missing docs entry that .count supports paranoid.
I also updated some internal dependencies and changed some to get patch updates instead of being fixed.

@BridgeAR

Copy link
Copy Markdown
Contributor Author

This might fix #3019. I'm not really sure though, since the query always returned as an empty array instead of a string as described in the issue.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't be expect(count).to.equal(0)?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nop - it's an array that is returned

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be an integer.
count([options]) -> Promise.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thx for pointing out that the docs are wrong

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It really should return a single value though, not an array.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a plain result with an array with one entry. The entry contains an object with count plus the attributes you provided as option.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That sounds like a regression then. It should result in a primitive afaik.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is probably related to the issue mentioned on IRC the other day @mickhansen

When grouping count will return several rows - we haven't really decided what should happen it this case

@cusspvz

cusspvz commented May 18, 2015

Copy link
Copy Markdown

I'm not really sure though, since the query always returned as an empty array instead of a string as described in the issue.

The root of this problem is that mysql returns an empty string when count is 0, and as sequelize wasn't parsing numeric results, it was returning NaN (because somewhere on sequelize's or our code, integers were being parsed).

@BridgeAR

Copy link
Copy Markdown
Contributor Author

If you use the group option, plain will be set to false. This has to be that way, since the return value might contain more than one entry. So if plain is set, the result will look like: [{count: 1}] or like [] if count is zero. The line you pointed at it will never be reached.
To solve your NaN it would be nice to get your code piece that fails, so I can help.

@cusspvz

cusspvz commented May 18, 2015

Copy link
Copy Markdown

To solve your NaN it would be nice to get your code piece that fails, so I can help.

I think this PR actually fixes it. Thanks for your disposal anyway :D

So if plain is set, the result will look like: [{count: 1}] or like [] if count is zero. The line you pointed at it will never be reached.

Didn't knew about group option. Seems right!

I think this PR is ready to be merged.
Great work @BridgeAR !! Thanks :)

@BridgeAR

Copy link
Copy Markdown
Contributor Author

After thinking about it: The only function call to convert the number is coming from the aggregate function. There could be big numbers parsed, but this is not very likely. This would be a BC if we change it now.

@BridgeAR BridgeAR changed the title Mysql: Fix Model.count returning NaN. Closes #3019 WIP: Mysql: Fix Model.count returning NaN. Closes #3019 May 20, 2015

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Connector-manager.test might be just about the worst place to add this test :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants