-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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(NODE-5374): do not apply cursor transform in Cursor.hasNext #3746
Conversation
2da8f1a
to
dd008e0
Compare
dd008e0
to
656e3cc
Compare
656e3cc
to
34424ed
Compare
8d644eb
to
9a4eecc
Compare
src/cursor/abstract_cursor.ts
Outdated
cursor: AbstractCursor<T>, | ||
blocking: boolean, | ||
callback: Callback<T | null> | ||
): void { | ||
transform = true |
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 assume we are defaulting to true
here as more methods would transform vs. methods that don't (hasNext
)?
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.
Yeah, that was my logic. I also considered two other options:
- providing no default
- combining
blocking
andtransform
into an options object and requiring all callsites to explicitly set them for clarity (i.e.,next(this, { blocking: true, transform: false })
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 lean towards providing no default, for internal I prefer to make each call site define its inputs and because this isn't saving us a lot of refactors. I don't feel strongly though, feel free to resolve if we agree to leave it as is.
Description
What is changing?
Primarily this PR fixes two bugs in our AbstractCursor.
hasNext
.To facilitate this, the generic
next<T>
was refactored to use async-await as well.The PR is broken down into commits which might be easier to view. The first commits are the async-await refactor, then the bug fixes.
Is there new documentation needed for these changes?
No.
What is the motivation for this change?
Release Highlight
Cursor.map transform bug fixes
The cursor API provides the ability to apply a
map
function to each document in the cursor:Cursor iteration properly catches errors thrown from the transform applied in
Cursor.map
Starting in version 4.0 of the driver, if the transform function throws an error, there are certain scenarios where the driver does not correctly catch this error and an uncaught exception is thrown:
This release adds logic to ensure that whenever we transform a cursor document, we handle any errors properly. Any errors thrown from a transform function are caught and returned to the user.
Cursor.hasNext no longer transforms documents if a transform has been applied to the cursor
Version 4.0 introduced a bug that would apply a
transform
function to documents in the cursor when the cursor was iterated usingCursor.hasNext()
. When combined withCursor.next()
, this would result in transforming documents multiple times.This release removes the transform logic from
Cursor.hasNext
, preventing cursor documents from being transformed twice when iterated usinghasNext
.Double check the following
npm run check:lint
scripttype(NODE-xxxx)[!]: description
feat(NODE-1234)!: rewriting everything in coffeescript