[CSHARP-1618] BsonDocument.Parse fails for some valid ISODate values Created: 04/Apr/16 Updated: 23/Sep/16 Resolved: 13/Apr/16 |
|
| Status: | Closed |
| Project: | C# Driver |
| Component/s: | BSON |
| Affects Version/s: | 1.11, 2.0.1 |
| Fix Version/s: | 2.3 |
| Type: | Bug | Priority: | Minor - P4 |
| Reporter: | Yaniv Weinberg | Assignee: | Robert Stam |
| Resolution: | Done | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Environment: |
Windows 2012 |
||
| Description |
|
VMware is using Mongo as part of its' Mirage product. ---> System.FormatException: String was not recognized as a valid DateTime format This caused our system to not recognize the Mongo state correctly. |
| Comments |
| Comment by Githook User [ 13/Apr/16 ] | ||||||||||||||||||||||
|
Author: {u'name': u'Robert Stam', u'email': u'Robert Stam'}Message: | ||||||||||||||||||||||
| Comment by Githook User [ 13/Apr/16 ] | ||||||||||||||||||||||
|
Author: {u'name': u'Robert Stam', u'email': u'Robert Stam'}Message: | ||||||||||||||||||||||
| Comment by Robert Stam [ 04/Apr/16 ] | ||||||||||||||||||||||
|
The initial assumption was that this exception was being thrown because the time component was using "." instead of ":" as a separator. According to ISO 8601 "." is not a valid separator. It can only be used to indicate fractions (usually fractions of a second). Another explanation might be that the string had only "HH:mm" (i.e no seconds or fractions of a second). We don't parse that correctly, even though it is valid according to ISO 8601 (the seconds are implied to be zero). There are other ISO 8601 variants we don't parse correctly either (for example, separators are optional). At the very least we should parse any variant we produce ourselves (either by a driver or any command line tool like the shell or mongoexport). It might be worth while supporting additional valid ISO 8601 formats, even the ones we might never produce ourselves. | ||||||||||||||||||||||
| Comment by Yaniv Weinberg [ 04/Apr/16 ] | ||||||||||||||||||||||
|
rs.status() returns the above block when run manually or through the code, this seems like a normal format. Anyway this is an FYI case, the issue is resolved once they moved to HH:mm | ||||||||||||||||||||||
| Comment by Robert Stam [ 04/Apr/16 ] | ||||||||||||||||||||||
|
The Shell syntax: ISODate("date-value") requires that the "date-value" string be in ISO 8601 format, which requires ":" as the separator (any local region settings on the computer are supposed to be ignored). Not sure how a document with an invalid "date-value" came into existence, but if it is not using ":" as the separator in "hh:mm:ss" then it is not a valid "date-value". | ||||||||||||||||||||||
| Comment by Yaniv Weinberg [ 04/Apr/16 ] | ||||||||||||||||||||||
|
I don't get it either, the customer has before we changed their format to HH:mm:ss and HH:mm | ||||||||||||||||||||||
| Comment by Robert Stam [ 04/Apr/16 ] | ||||||||||||||||||||||
|
I don't get any exception when parsing that string with BsonDocument.Parse. Do you mean that you get an exception parsing that string on a system with the regional settings set to Italian? | ||||||||||||||||||||||
| Comment by Yaniv Weinberg [ 04/Apr/16 ] | ||||||||||||||||||||||
|
I just guess that there are other formats which may break this other than "." as separator. An example of what it couldn't parse on a system with the "." seperator.
The editor has wonked up the spaces a bit, sorry | ||||||||||||||||||||||
| Comment by Robert Stam [ 04/Apr/16 ] | ||||||||||||||||||||||
|
I'm not sure about relying on the regional settings... it doesn't necessarily agree with the representation used by the data. Normally all data stored in or coming from a database should be in a culture invariant format. It should be up to the presentation layer to convert to local region and timezone for display purposes. In this case it looks like you are invoking the shell to execute "rs.status()" and then capturing and parsing what was sent to standard output. Another approach would be to directly execute whatever command(s) rs.status() calls, which would avoid having to parse a string at all. Regarding the parsing error, a good general rule is to be strict when writing data and forgiving when reading it, so it seems like we could relax our parsing code to work with either ":"or "." as the separator (regardless of region settings). | ||||||||||||||||||||||
| Comment by Craig Wilson [ 04/Apr/16 ] | ||||||||||||||||||||||
|
Could you provide an example document that failed to parse so we can reproduce this? | ||||||||||||||||||||||
| Comment by Yaniv Weinberg [ 04/Apr/16 ] | ||||||||||||||||||||||
|
I mean the HH.mm.ss format instead of HH:mm:ss |