[GODRIVER-1720] replace_one does not validate all keys for update operators Created: 16/Aug/20 Updated: 27/Oct/23 Resolved: 18/Aug/20 |
|
| Status: | Closed |
| Project: | Go Driver |
| Component/s: | None |
| Affects Version/s: | None |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Major - P3 |
| Reporter: | Shrey Batra | Assignee: | Divjot Arora (Inactive) |
| Resolution: | Works as Designed | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Description |
|
When using replace_one function, it only checks for the first argument to see if it is update operator or not. If first key is an update operator, it raises ValueError, whereas if it's after a valid key, it raises a WriteError from the server. This should be caught at the driver level instead of server level. Example -
The above line raises a ValueError, whereas the below line raises a WriteError
|
| Comments |
| Comment by Divjot Arora (Inactive) [ 18/Aug/20 ] |
|
Per this CRUD specification section, drivers are only supposed to validate the first key. In the case of UpdateOne/UpdateMany, we ensure that the first key starts with $. For ReplaceOne, we ensure the first key does not start with $. It's sufficient to just check the first key because the server will error if the first key starts with $ and any other keys do not, or vice versa. I understand that it can be confusing to get a client-side error in one case and a server-side error in a separate case, but introspecting all keys could have a performance impact for large update/replacement documents, which would be a non-starter. Given that, I'm going to close this ticket out as "works as designed". Feel free to leave another comment or file a new ticket if you have any other questions, though. – Divjot |