[CSHARP-4799] Pipeline stage with BsonDocumentSearchDefinition can be rendered only once Created: 20/Sep/23 Updated: 28/Oct/23 Resolved: 04/Oct/23 |
|
| Status: | Closed |
| Project: | C# Driver |
| Component/s: | None |
| Affects Version/s: | None |
| Fix Version/s: | 2.22.0 |
| Type: | Bug | Priority: | Major - P3 |
| Reporter: | Boris Dogadov | Assignee: | Boris Dogadov |
| Resolution: | Fixed | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Documentation Changes: | Not Needed |
| Documentation Changes Summary: | 1. What would you like to communicate to the user about this feature? |
| Description |
|
The issue as described to me by Boris is that if a caller to Render modifies the returned BsonDocument then a subsequent call to Render returns the modified BsonDocument. This could be resolved by clarifying ownership rules of the mutable BsonDocument. Only the owner of the BsonDocument should modify it. Most likely this would mean that that BsonDocumentSearchDefinition should own the BsonDocument, which in turn means that callers to Render should not modify the returned BsonDocument because they don't own it. However, such a rule can't be enforced at compile time because BsonDocument is mutable. Alternatively, BsonDocumentSearchDefinition could make a defensive copy of the BsonDocument before returning it from Render (and possibly in the constructor as well to protect the document even further). This approach would be safe but involves more memory allocations. |
| Comments |
| Comment by Githook User [ 04/Oct/23 ] |
|
Author: {'name': 'BorisDog', 'email': 'BorisDog@users.noreply.github.com', 'username': 'BorisDog'}Message: |
| Comment by Robert Stam [ 20/Sep/23 ] |
|
Note that there are other similar classes that return an owned BsonDocument from their Render method on the assumption that callers won't modify the returned BsonDocument. So the consistent thing to do would be for callers of this Render method to also not modify the returned BsonDocument. |