[CSHARP-4809] If a string serializer doesn't implement IHasRepresentationSerializer don't assume string values are actually represented as strings Created: 13/Oct/23 Updated: 26/Oct/23 Resolved: 26/Oct/23 |
|
| Status: | Closed |
| Project: | C# Driver |
| Component/s: | LINQ3 |
| Affects Version/s: | None |
| Fix Version/s: | 2.23.0 |
| Type: | Bug | Priority: | Unknown |
| Reporter: | Donald Frederick | Assignee: | Robert Stam |
| Resolution: | Fixed | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Attachments: |
|
| Backwards Compatibility: | Fully Compatible |
| Documentation Changes: | Not Needed |
| Documentation Changes Summary: | 1. What would you like to communicate to the user about this feature? |
| Description |
SummaryApologies if I miss something expected, just joined the project so I could report this. I'm encountering a bug where the LINQ3 provider is not matching a document for update, but LINQ2 provider works.
Please provide the version of the driver. If applicable, please provide the MongoDB server version and topology (standalone, replica set, or sharded cluster).MongoDB.Driver 2.22.0 (worked with MongoDB.Driver 2.16.1)MongoDB 6.04 replicaset How to ReproduceSteps to reproduce. If possible, please include a Short, Self Contained, Correct (Compilable), Example. add an appsettings.json file with
_ { "ConnectionStrings": \{ "MongoConnectionString": "<<<mongo connection string here>>>" }}_ in Program.cs add this code
_using MongoDB.Bson.Serialization.Serializers; else to a String."; [BsonSerializer(typeof(ObjectIdSerializer))] [BsonElement("d")] Run with useLinq3 = false Run with useLinq3 = true open a mongodb client and query the docs in the RootDocuments collection expected: actual: the doc when linq3 is used still has "sd" : null instead of the subdocument being saved
Additional BackgroundPlease provide any additional background information that may be helpful in diagnosing the bug. |
| Comments |
| Comment by Githook User [ 26/Oct/23 ] |
|
Author: {'name': 'rstam', 'email': 'robert@robertstam.org', 'username': 'rstam'}Message: |
| Comment by Robert Stam [ 16/Oct/23 ] |
|
The core issue here is that the LINQ translator has no way of determining whether your custom serializer actually stores C# string values as strings in the database, which in your case it does not (it converts them to ObjectIds). The way the LINQ provider tries to determine whether a string serializer actually stores string values as strings in the database is by checking to see if the serializer implements the IRepresentationConfigurable interface, which your custom serializer does not. The current code assumes that a string serializer does in fact store strings as strings (a reasonable assumption). Since this assumption is not guaranteed to be correct, we will be changing the code to assume the opposite: unless we can determine for sure that a string serializer actually stores string values as strings we will assume it does not. This is the safer assumption. The consequence is that in such a case we won't ever translate any C# string expressions to MQL regexes. Note: while the current code uses IRepresentationConfigurable to determine how a string serializer actually represents string values in the database, we will be switching to using the IHasRepresentationSerializer interface. In other words, we only need to determine the serialized representation, it doesn't matter if it is configurable or not. |
| Comment by Boris Dogadov [ 13/Oct/23 ] |
|
Thank you for submitting this issue and the reproduction code frederick.donald@gmail.com. We have reproduced this behavior and will be looking further into this. Please follow this ticket for further updates. |
| Comment by Donald Frederick [ 13/Oct/23 ] |
|
Apologies, discovered new information while creating this bug, and forgot to update the title. If someone is able to edit, please change it to something more descriptive. I suggest "LINQ3 filter on id with custom bsonserializer doesn't seem to be respected causing no match" |
| Comment by PM Bot [ 13/Oct/23 ] |
|
Hi frederick.donald@gmail.com, thank you for reporting this issue! The team will look into it and get back to you soon. |