[CSHARP-1957] UpdateDefinitionBuilder fails when stated type does not match field type Created: 05/Apr/17 Updated: 01/May/17 Resolved: 10/Apr/17 |
|
| Status: | Closed |
| Project: | C# Driver |
| Component/s: | Linq |
| Affects Version/s: | 2.4.2, 2.4.3 |
| Fix Version/s: | 2.4.4 |
| Type: | Bug | Priority: | Major - P3 |
| Reporter: | Martin Lobger | Assignee: | Robert Stam |
| Resolution: | Done | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Environment: |
Windows |
||
| Attachments: |
|
| Description |
|
When using UpdateDefinitionBuilder to update a document property of any enumerable parsing in an object, the serializer will change the property from type array to type object adding _t and _v. Adding these unit tests to UpdateDefinitionBuilderTests will expose the problem:
I have also attached a small .net program that simulates what I am doing in order to get this error. |
| Comments |
| Comment by Githook User [ 10/Apr/17 ] | |||||||||||||||||||||||
|
Author: {u'username': u'rstam', u'name': u'rstam', u'email': u'robert@robertstam.org'}Message: | |||||||||||||||||||||||
| Comment by Githook User [ 10/Apr/17 ] | |||||||||||||||||||||||
|
Author: {u'username': u'rstam', u'name': u'rstam', u'email': u'robert@robertstam.org'}Message: | |||||||||||||||||||||||
| Comment by Githook User [ 10/Apr/17 ] | |||||||||||||||||||||||
|
Author: {u'username': u'rstam', u'name': u'rstam', u'email': u'robert@robertstam.org'}Message: | |||||||||||||||||||||||
| Comment by Robert Stam [ 07/Apr/17 ] | |||||||||||||||||||||||
|
This isn't directly related to enumerables. I can reproduce the essence of the issue using these simple classes:
and this code:
which results in this update statement being generated:
This issue is only occurring because the Set statement was forced to use type <object> instead of the actual type which is <D>. | |||||||||||||||||||||||
| Comment by Martin Lobger [ 05/Apr/17 ] | |||||||||||||||||||||||
|
Finally figured out why the Program.cs was working in 2.4.1 It was because I was using an interface IEnumerable instead of a concrete implementation. If I change IEnumerable<UserData> to List<UserData> 2.4.1 will fail as well. So in that sense, 2.4.2 is more consistent. But it leads down to the EnumerableSerializerBase<TValue, TItem> class in the method:
I suggest changing the line
to
RETRACTION: This will fix it for 2.4.1 but apparently not for 2.4.3 | |||||||||||||||||||||||
| Comment by Martin Lobger [ 05/Apr/17 ] | |||||||||||||||||||||||
|
When running Program.cs the document looks like this in the mongodb after the insert operation:
And after the update the document looks like this:
| |||||||||||||||||||||||
| Comment by Martin Lobger [ 05/Apr/17 ] | |||||||||||||||||||||||
|
This little console application works when using nuget mongo.driver 2.4.1 but fails when using nuget mongo.driver 2.4.2 or later | |||||||||||||||||||||||
| Comment by Martin Lobger [ 05/Apr/17 ] | |||||||||||||||||||||||
|
I just realized that the unit tests I suggested, also fails on v2.4.1 However, the Program.cs will behave as (I would) expected using Nuget Mongo.Driver v2.4.1 but introduces the _t & _v when run using Nuget Mongo.Driver v2.4.2 and forward. The problem is not (de)serializing the document afterwards, the problem is that all "find" operation will fail after the update. |