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

Fixed empty blob #9441

Merged
merged 2 commits into from May 19, 2018
Merged

Fixed empty blob #9441

merged 2 commits into from May 19, 2018

Conversation

@YaroslavRepeta
Copy link
Contributor

@YaroslavRepeta YaroslavRepeta commented May 15, 2018

Pull Request check-list

Please make sure to review and check all of these items:

  • Does npm run test or npm run test-DIALECT pass with this change (including linting)?
  • Does the description below contain a link to an existing issue (Closes #[issue]) or a description of the issue you are solving?
  • Have you added new tests to prevent regressions?
  • Is a documentation update included (if this change modifies existing APIs, or introduces new ones)?
  • Did you follow the commit message conventions explained in CONTRIBUTING.md?

Description of change

SELECT query returns null instead of empty Buffer for BLOB type

Yaroslav Repeta
@codecov
Copy link

@codecov codecov bot commented May 15, 2018

Codecov Report

Merging #9441 into master will increase coverage by <.01%.
The diff coverage is n/a.

@@ -43,13 +43,7 @@ module.exports = BaseTypes => {
inherits(BLOB, BaseTypes.BLOB);

BLOB.parse = function(value, options, next) {
const data = next();

This comment has been minimized.

@sushantdhiman

sushantdhiman May 18, 2018
Contributor

I dont think this works, can you show me a failing case

This comment has been minimized.

@YaroslavRepeta

YaroslavRepeta May 18, 2018
Author Contributor

I'm not sure where the right place to add test case for this.

What I did here is only removed if what causes returning null instead of empty buffer.

This comment has been minimized.

@sushantdhiman

sushantdhiman May 18, 2018
Contributor

Ok show me example of what you are trying to solve, paste it here

This comment has been minimized.

@YaroslavRepeta

YaroslavRepeta May 18, 2018
Author Contributor

Something like:

expect(
    (await model.findOne({ some_where_clause })).empty_buffer_column
).to.equal(Buffer.from(""));

In fact mysql2 what is used returns empty buffer in select queries, when sequelize catches that and returns null instead.

@sushantdhiman
Copy link
Contributor

@sushantdhiman sushantdhiman commented May 19, 2018

Ok so I have tested this change

User
  .sync({ force: true })
  .then(() => {
    return User.bulkCreate([{
      username: 'anc',
      data: Buffer.from('')
    }, {
      username: 'anc',
      data: null
    }]);
  })
  .then(() => {
    return User.findAll();
  })
  .then(users => {
    console.log(users[0].data, users[1].data);
  });

### Output
<Buffer > null

It seems MySQL2 now handles null case correctly, so as expected binary null should be returned as null but empty buffer should be returned as buffer.

If you can add a test around here https://github.com/sequelize/sequelize/blob/master/test/integration/model.test.js#L2526 It seems we already have a test for null case

expect(user.data).to.be.null;
, so no need to add new test

Some related issues #8661 sidorares/node-mysql2#668

@@ -43,13 +43,7 @@ module.exports = BaseTypes => {
inherits(BLOB, BaseTypes.BLOB);

BLOB.parse = function(value, options, next) {

This comment has been minimized.

@sushantdhiman

sushantdhiman May 19, 2018
Contributor

Remove BLOB function from this file, we will now go with mysql2 default

Yaroslav Repeta
@sushantdhiman sushantdhiman merged commit 1bcfaa7 into sequelize:master May 19, 2018
4 checks passed
4 checks passed
codecov/patch Coverage not affected when comparing 7b7b23d...d4db736
Details
codecov/project 95.97% (+<.01%) compared to 7b7b23d
Details
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

2 participants