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

fix(NODE-5044): Write Concern 0 Must Not Affect Read Operations (#3541) #3575

Merged
merged 4 commits into from Feb 22, 2023

Conversation

baileympearson
Copy link
Contributor

@baileympearson baileympearson commented Feb 17, 2023

Description

What is changing?

Cherry-picked changes from the 4.x branch with the same fix.

Is there new documentation needed for these changes?

no.

Double check the following

  • Ran npm run check:lint script
  • Self-review completed using the steps outlined here
  • PR title follows the correct format: type(NODE-xxxx)[!]: description
    • Example: feat(NODE-1234)!: rewriting everything in coffeescript
  • Changes are covered by tests
  • New TODOs have a related JIRA ticket

Co-authored-by: Neal Beeken <neal.beeken@mongodb.com>
@baileympearson baileympearson changed the title fix(NODE-4999): Write Concern 0 Must Not Affect Read Operations (#3541) fix(NODE-5044): Write Concern 0 Must Not Affect Read Operations (#3541) Feb 17, 2023
@baileympearson baileympearson marked this pull request as ready for review February 17, 2023 15:09
@nbbeeken nbbeeken added the Primary Review In Review with primary reviewer, not yet ready for team's eyes label Feb 17, 2023
@nbbeeken nbbeeken self-requested a review February 17, 2023 15:50
src/change_stream.ts Show resolved Hide resolved
src/operations/find.ts Show resolved Hide resolved
test/integration/read-write-concern/write_concern.test.ts Outdated Show resolved Hide resolved
test/integration/read-write-concern/write_concern.test.ts Outdated Show resolved Hide resolved
test/integration/read-write-concern/write_concern.test.ts Outdated Show resolved Hide resolved
test/integration/read-write-concern/write_concern.test.ts Outdated Show resolved Hide resolved
test/integration/read-write-concern/write_concern.test.ts Outdated Show resolved Hide resolved
src/operations/list_collections.ts Show resolved Hide resolved
src/operations/indexes.ts Show resolved Hide resolved
Comment on lines 399 to 401
// @ts-expect-error Write concern is disallowed in types, but
// must still be removed in case the user is not using Typescript
delete this.options.writeConcern;
Copy link
Contributor

Choose a reason for hiding this comment

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

Interesting that we need ts-expect-error in src code, is there another way we could organize this? (can be in a follow up)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not with strong typing. I mean, ultimately the real fix is to pass the full operation all the way down to the command layer, so that when we apply the session, we have access to the operation class and can check if it has a read aspect.

Copy link
Contributor

Choose a reason for hiding this comment

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

If we're creating a new object, then can their be a new type that allows deleting the writeConcern without a ts-expect-error?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do you mean like an internal options type? Does that not seem like overkill?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also, how / why would we type something such that it allows the existence of a property that we will always delete?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What do you mean by types not being true? The type is correct. The argument could be made that we should omit this logic entirely because if someone passes a write concern to read operation and our types no longer support it, they are operating outside the bounds of our API.

Copy link
Contributor

Choose a reason for hiding this comment

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

I thought the issue was with the option being inherited rather than being directly passed, right?
I think if it was a correct type then we wouldn't need ts-expect-error

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point about options being inherited.

I don't think the value of modifying the type to include writeConcern?: never is worthwhile. I don't think that's the correct fix (I mention what I believe the correct fix to be above), so I'm going to leave this as-is.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Alternative option, again outside the scope of this work, is to consider a generic approach to constructing the options objects we use internally. Each command would construct an options object, only assigning the options that are actually supported for that command, instead of spreading all the existing options (maybe add an abstract parseOptions(userOptions, inheritedOptions) : OptionInterface method that each command implements). But that is a larger change that impacts the driver as a whole, so I won't address it here.

Copy link
Contributor

Choose a reason for hiding this comment

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

I seem to recall a ticket related to that idea was a part of the Operation Layer Unification epic we used to have but I can't seem to find it, seems worth filing something for esp if we've considered it before.

I'd prefer if we made the types accurate rather than putting in compiler overrides

src/change_stream.ts Show resolved Hide resolved
Copy link
Contributor

@nbbeeken nbbeeken left a comment

Choose a reason for hiding this comment

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

requested changes already ^ bump

Copy link
Contributor

@nbbeeken nbbeeken left a comment

Choose a reason for hiding this comment

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

Lgtm

@nbbeeken nbbeeken added Team Review Needs review from team and removed Primary Review In Review with primary reviewer, not yet ready for team's eyes labels Feb 22, 2023
@nbbeeken nbbeeken merged commit 10146a4 into main Feb 22, 2023
@nbbeeken nbbeeken deleted the NODE-5044 branch February 22, 2023 16:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Team Review Needs review from team
Projects
None yet
3 participants