Skip to content

feat: allow validating bulk load parameters - #1065

Merged
arthurschreiber merged 1 commit into
tediousjs:masterfrom
MichaelSun90:DateTypeBulkChanges
Aug 16, 2020
Merged

arthurschreiber merged 1 commit into
tediousjs:masterfrom
MichaelSun90:DateTypeBulkChanges

Conversation

@MichaelSun90

Copy link
Copy Markdown
Contributor

Validate function will report error is input data do not match the data type check. However, the current bulk logic does not expose this error. Added some logic to expose these errors.

Related issue: #889

@arthurschreiber

Copy link
Copy Markdown
Collaborator

@MichaelSun90 Can you add a test case for this?

@codecov

codecov Bot commented Mar 5, 2020 •

Copy link
Copy Markdown

Codecov Report

Merging #1065 into master will decrease coverage by 1.41%.
The diff coverage is 93.10%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1065      +/-   ##
==========================================
- Coverage   81.35%   79.93%   -1.42%     
==========================================
  Files          86       86              
  Lines        4413     4415       +2     
  Branches      806      802       -4     
==========================================
- Hits         3590     3529      -61     
- Misses        564      623      +59     
- Partials      259      263       +4     
Impacted Files Coverage Δ
src/bulk-load.ts 80.98% <91.66%> (+0.57%) ⬆️
src/connection.ts 61.16% <100.00%> (-5.16%) ⬇️
src/token/env-change-token-parser.ts 55.81% <0.00%> (-23.26%) ⬇️
src/connector.ts 93.54% <0.00%> (-6.46%) ⬇️
src/token/token.ts 88.03% <0.00%> (-3.42%) ⬇️
src/data-types/uniqueidentifier.ts 77.77% <0.00%> (-2.23%) ⬇️
src/token/nbcrow-token-parser.ts 75.00% <0.00%> (-0.87%) ⬇️
src/incoming-message-stream.ts 92.30% <0.00%> (-0.38%) ⬇️
... and 20 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d336445...bb176fd. Read the comment docs.

@arthurschreiber

Copy link
Copy Markdown
Collaborator

Thanks for providing a test case! 🙇 I think we should also add a test case for streaming bulk loads? I have a hunch that the change will not work for streaming bulk loads in its current form. 🤔

Comment thread src/connection.ts Outdated
throw new TypeError('The "config.options.validateBulkLoadParameters" property must be of type boolean.');
}

deprecate('This "validateBulkLoadParameters" property will be depercated in the next major version of `tedious`.');

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.

I am not sure that I suppose to add the message here. I thought that users may want to know that this property is going to be deprecated when they are actually using it which means that when "config.options.validateBulkLoadParameters !== undefined". However, I am not sure whether I am correct about this.

@arthurschreiber
arthurschreiber force-pushed the DateTypeBulkChanges branch 2 times, most recently from a6e36eb to 0fa4521 Compare April 14, 2020 05:54
@arthurschreiber arthurschreiber changed the title refactor: add a error throw for bulk logic feat: allow validating bulk load parameters Apr 14, 2020
Comment thread test/unit/bulk-load-test.js Outdated
Comment on lines +15 to +19
try {
request.addRow({ columnName: 'Wrong Input' });
} catch (err) {
assert.strictEqual(err.message, 'Invalid date.');
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think this should use the assert.throws helper:

Suggested change
try {
request.addRow({ columnName: 'Wrong Input' });
} catch (err) {
assert.strictEqual(err.message, 'Invalid date.');
}
assert.throws(() => {
request.addRow({ columnName: 'Wrong Input' });
}, TypeError, 'Invalid date.');

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.

Oh, sure. There are few other tests in this test file that also using strictEqual, should I also modify them as well?

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.

Nvm, those are under "\test\integration\bulk-load-test.js" 😅

Comment thread src/connection.ts

this.config.options.validateBulkLoadParameters = config.options.validateBulkLoadParameters;
} else {
deprecate('The default value for "config.options.validateBulkLoadParameters" will change from `false` to `true` in the next major version of `tedious`. Set the value to `true` or `false` explicitly to silence this message.');

@MichaelSun90 MichaelSun90 Apr 14, 2020 •

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.

Will this be a better message ? "This "validateBulkLoadParameters" property will be deprecated in the next major version of tedious."

@arthurschreiber arthurschreiber Apr 18, 2020 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think we'll want this to be a 2 step process:

  • First, we introduce the validateBulkLoadParameters flag, but keep defaulting to false. (minor release)
  • Then, we switch the default to true. (major release)
  • We deprecate setting the validateBulkLoadParameters flag to anything but true. (minor release)
  • Eventually, we drop the validateBulkLoadParameters flag. (major release)

Comment thread src/bulk-load.ts
const error = c.type.validate(row[i]);

if (error instanceof TypeError) {
return callback(error);

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.

Hi @arthurschreiber, since the error is not thrown here, we need additional handling for the error under "addRow" method, right?

@oanylund

oanylund commented Apr 22, 2020 •

Copy link
Copy Markdown

Hi, was just about to report an issue but found this feature that looks like it will fix it.
The added callback in the transform stream looks promising. I just spent one hour trying to catch an unhandled exception from the stream. 😄
The compiled lib today adds a try catch around the "for of chunk" wich if fails and eventually throws an _iteratorError in the _write method of the RowTransform. Adding a callback with error allows better error handling in general from outside the library.

Compiled part:
try { for (var _iterator = c.type.generateParameterData(parameter, this.mainOptions)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { const chunk = _step.value; this.push(chunk); } } catch (err) { _didIteratorError = true; _iteratorError = err; } finally { try { if (!_iteratorNormalCompletion && _iterator.return != null) { _iterator.return(); } } finally { if (_didIteratorError) { throw _iteratorError; } } }

In the Node.js documentation this is mentioned: "Throwing an Error from within these methods or manually emitting an 'error' event results in undefined behavior."


it('should test stream bulk load', function(done) {
this.timeout(50000);
this.timeout(200000);

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.

change this because of that this test always gives me a time out error. Increase this make the test pass.

This adds a new `validateBulkLoadParameters` connection option that allows toggling bulk load
parameter validation. This new option defaults to `false`, but will emit a deprecation warning
if not set, and will change its default to `true` in the future.
@arthurschreiber
arthurschreiber merged commit 3c8be98 into tediousjs:master Aug 16, 2020
@github-actions

Copy link
Copy Markdown
Contributor

🎉 This PR is included in version 9.2.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants