CXuesong / WikiClientLibrary

/*🌻*/ Wiki Client Library is an asynchronous MediaWiki API client library targeting modern .NET platforms
https://github.com/CXuesong/WikiClientLibrary/wiki
Apache License 2.0
80 stars 16 forks source link

ArgumentException for WbGlobeCoordinate with precision = null #106

Open j-bbr opened 10 months ago

j-bbr commented 10 months ago

During processing of a recent wikidata dump I noticed that WbGlobeCoordinate throws an ArgumentException if the precision field is null. Here is the relevant portion from an example entity (Berlin TV Tower) from the dump where that occurs:

"P625": [
            {
                "mainsnak": {
                    "snaktype": "value",
                    "property": "P625",
                    "datavalue": {
                        "value": {
                            "latitude": 52.520833333333,
                            "longitude": 13.409444444444,
                            "altitude": null,
                            "precision": null,
                            "globe": "http:\/\/www.wikidata.org\/entity\/Q2"
                        },
                        "type": "globecoordinate"
                    },
                    "datatype": "globe-coordinate"
                },
                "type": "statement",
                "id": "q151356$2200165A-750E-42AB-BC62-4F23EF25F202",
                "rank": "normal"
            }
        ]

Maybe the precision field could be made nullable in WbGlobeCoordinate?

mormegil-cz commented 10 months ago

Just came here to report the same! I’m surprised this is allowed on Wikidata/Wikibase side, but it apparently occurs (for me, this was Q744598). In the Wikidata UI, the precision (shown when editing the claim) is shown as “unspecified”, but it cannot be set to unspecified after choosing anything else; strange.

For completeness, the exception callstack is

System.ArgumentException: Can not convert Null to Double.
   at Newtonsoft.Json.Linq.JToken.op_Explicit(JToken value)
   at WikiClientLibrary.Wikibase.DataTypes.BuiltInDataTypes.<>c.<.cctor>b__46_19(JToken e)
   at WikiClientLibrary.Wikibase.DataTypes.DelegatePropertyType`1.Parse(JToken expr)
   at WikiClientLibrary.Wikibase.Snak.get_DataValue()