Page MenuHomePhabricator

globecoordinate serialization fails on some precision values
Closed, ResolvedPublic

Description

I'm writing a bot to import coordinates to Wikidata and I ran into problems with the "precision" field. For a lot of values it throws 'The value does not comply with the property's definition.
The value's data value type "ununserializable" does not match the property's data type's data value type "globecoordinate".'

Example json:
{'latitude': 41.9689, 'altitude': None, 'globe': 'http://www.wikidata.org/entity
/Q2', 'longitude': 12.4092, 'precision': 0.012082121278963331}

I did some testing on https://www.wikidata.org/wiki/Q3969823

  • 0.012039052310050358 fails
  • 0.012058 fails (round on 6 decimals)
  • 0.00001 works (hard coded)
  • 0.00002 fails (hard coded)

Version: unspecified
Severity: normal
Whiteboard: u=dev c=frontend p=0
See Also:
https://bugzilla.wikimedia.org/show_bug.cgi?id=63063

Details

Reference
bz62105

Event Timeline

bzimport raised the priority of this task from to High.Nov 22 2014, 3:07 AM
bzimport set Reference to bz62105.
bzimport added a subscriber: Unknown Object (MLST).

Ok. Did some digging. The type is defined at https://meta.wikimedia.org/wiki/Wikidata/Data_model#Geographic_locations

a precision (decimal, representing degrees of distance, defaults to 0, 9 digits after the dot and three before, unsigned, used to save the precision of the representation)

After some digging I found http://git.wikimedia.org/blob/mediawiki%2Fextensions%2FDataValues.git/727ccd66b03f42e1f5458ea204ca15b315cf5f04/DataValues%2Fresources%2FglobeCoordinate.js%2Fsrc%2FglobeCoordinate.GlobeCoordinate.js

function isValidPrecision( precision ) {

    var precisions = globeCoordinate.GlobeCoordinate.PRECISIONS;
 
    for( var i in precisions ) {
        if( Math.abs( precision - precisions[i] ) < 0.0000001 ) {
            return true;
        }
    }
 
    return false;
}
 
/**
 * Precisions a globe coordinate may feature.
 * @type {number[]}
 */
GlobeCoordinate.PRECISIONS = [
    10,
    1,
    0.1,
    1 / 60,
    0.01,
    0.001,
    1 / 3600,
    0.0001,
    1 / 36000,
    0.00001,
    1 / 360000,
    0.000001,
    1 / 3600000
];

So it looks like only these values (with a minor deviation of 0.0000001) are considered valid. Is this true? Is this intentional? Where the hell is this documented? If this is true, why does the api accept invalid precisions?

  • This bug has been marked as a duplicate of bug 64887 ***