[GODRIVER-2281] IsDuplicateKeyError does not work on individual bulk write errors Created: 24/Jan/22 Updated: 10/Feb/22 Resolved: 03/Feb/22 |
|
| Status: | Closed |
| Project: | Go Driver |
| Component/s: | None |
| Affects Version/s: | 1.8.2 |
| Fix Version/s: | 1.9.0 |
| Type: | Improvement | Priority: | Unknown |
| Reporter: | Nicolas Nannoni | Assignee: | Benji Rewis (Inactive) |
| Resolution: | Done | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Documentation Changes: | Not Needed |
| Description |
|
mongo.IsDuplicateKeyError is a convenient helper to detect duplicates. It however does not work when the duplicate key error is returned as part of a bulk. While it will tell whether any of the errors in the bulk was a duplicate, it can't be applied to the individual errors (of type BulkWriteError) within the BulkWriteException unless I missed a conversion somewhere.
It's a bit limiting since it's hard to decide what do with a whole batch just knowing that at least one of the operations failed due to a duplicate key error. Iterating on the errors in the bulk should allow mongo.IsDuplicateKeyError to be applied to them and return true if relevant. It has a code and a message so the same logic as for serverError should be applicable.
|
| Comments |
| Comment by Githook User [ 10/Feb/22 ] |
|
Author: {'name': 'Benjamin Rewis', 'email': '32186188+benjirewis@users.noreply.github.com', 'username': 'benjirewis'}Message: |
| Comment by Benji Rewis (Inactive) [ 03/Feb/22 ] |
|
Implemented ServerError for WriteError. This improvement will be a part of version 1.9.0 of the Go driver. |
| Comment by Githook User [ 03/Feb/22 ] |
|
Author: {'name': 'Benjamin Rewis', 'email': '32186188+benjirewis@users.noreply.github.com', 'username': 'benjirewis'}Message: |
| Comment by Nicolas Nannoni [ 02/Feb/22 ] |
|
Great, thank you! |
| Comment by Benji Rewis (Inactive) [ 02/Feb/22 ] |
|
Thanks again for your improvement suggestion, nicolas.nannoni@accedo.tv! WriteError does not implement ServerError, so the type cast in IsDuplicateKeyError does not work correctly. WriteErrors do, as you mentioned, contain both a Code and a Message , so implementing the interface should be easy enough. Here's a PR to do so. |
| Comment by Benji Rewis (Inactive) [ 01/Feb/22 ] |
|
Hello nicolas.nannoni@accedo.tv! Thanks for your improvement suggestion; we're taking a look now. |