Skip to content

Assert unset BulkWriteException.partialResult in CRUD prose tests #1785

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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

kevinAlbs
Copy link
Contributor

@kevinAlbs kevinAlbs commented Apr 9, 2025

Summary

Assert unset BulkWriteException.partialResult in CRUD prose tests.

Background & Motivation

CDRIVER-5969 identified an implementation bug. Empty (rather than unset) results were sometimes returned on client errors.

The assert is optional. These cases do not require throwing a BulkWriteException. Quoting spec:

When a top-level error is encountered and individual results and/or errors have already been observed, drivers MUST embed the top-level error within a BulkWriteException as the error field to retain this information. Otherwise, drivers MAY throw an exception containing only the top-level error.

If acceptable, will file a DRIVERS ticket for the test tweak (will likely be a spec-fest change).


Please complete the following before merging:

  • [ ] Update changelog. (Tests only)
  • Test changes in at least one language driver. (Tested in C driver)
  • [ ] Test these changes against all server versions and topologies (including standalone, replica set, sharded
    clusters, and serverless).
    (Tested on all but serverless. C does not test serverless).

Identifies a bug in the C driver implementation.
`BulkWriteError` is referenced in CRUD spec, but not the `MongoClient.bulkWrite` spec.
Copy link
Contributor

@isabelatkinson isabelatkinson left a comment

Choose a reason for hiding this comment

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

@@ -583,7 +583,7 @@ InsertOne {
```

Execute `bulkWrite` on `client` with `largeDocumentModel`. Assert that an error (referred to as `error`) is returned.
Assert that `error` is a client error.
Assert that `error` is a client error. Assert the returned `BulkWriteException.partialResult` is unset.
Copy link
Contributor

Choose a reason for hiding this comment

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

The Rust driver returns an InvalidArgument error rather than a BulkWriteError for these cases in line with the language from this section of the spec:

When a top-level error is encountered and individual results and/or errors have already been observed, drivers MUST embed the top-level error within a BulkWriteException as the error field to retain this information. Otherwise, drivers MAY throw an exception containing only the top-level error.

i.e., the invalid argument error is the "top-level" error, and no other errors or results have been observed, so we don't construct a wrapper BulkWriteError.

I'm still in favor of adding this assertion, but I think we should relax the language to be something like: "If a BulkWriteException was thrown, assert that partialResult is unset." I'll likely add assertions to the Rust tests that the error kind is indeed InvalidArgument.

Ditto for the other additions in this PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Great catch. Updated.

Driver is not required to raise `BulkWriteException` for a top-level error when no other results have been reported. Make the assertion optional.
@kevinAlbs kevinAlbs changed the title Assert unset BulkWriteResult.partialResult in CRUD prose tests Assert unset BulkWriteException.partialResult in CRUD prose tests Apr 10, 2025
Copy link
Contributor

@isabelatkinson isabelatkinson left a comment

Choose a reason for hiding this comment

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

lgtm!

@kevinAlbs kevinAlbs requested review from GromNaN and removed request for jmikola April 16, 2025 18:48
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.

2 participants