ArthurPSmith created this task.
ArthurPSmith added a subscriber: ArthurPSmith.
ArthurPSmith added projects: Wikidata, Pywikibot-Wikidata, pywikibot-core.
Herald added subscribers: pywikibot-bugs-list, StudiesWorld, Aklapper.

TASK DESCRIPTION
  pywikibot was recently updated to better handle decimal values - see this 
gerrit code change: https://gerrit.wikimedia.org/r/#/c/250497/ - however, as I 
noted there in a comment at the end, there is a problem with very small values 
(and I believe also for very large ones) which the formatter converts to 
exponential notation. The Wikidata API does not accept numbers for quantity 
values formatted with exponential notation. Either the formatter on the 
pywikibot side needs to be smarter in converting values to a standard decimal 
value the API understands, or the API needs to be more generous in accepting 
scientific notation.
  
  Here's the symptom of the problem: I tried adding  a "proportion" qualifier 
value that is 1.9e-9. I get the following warning and stack trace:
  WARNING: API error invalid-snak: Invalid snak (Value must match the pattern 
for decimal values.)
  
    Traceback (most recent call last):
    File "pwb.py", line 248, in <module>
      if not main():
     ...
      claim.addQualifier(prop_qual, bot=True, summary="Adding branching 
fraction qualifier from NNDC.")
    File ".../core/pywikibot/page.py", line 4404, in addQualifier
      data = self.repo.editQualifier(self, qualifier, **kwargs)
    File ".../core/pywikibot/site.py", line 1297, in callee
      return fn(self, *args, **kwargs)
    File ".../core/pywikibot/site.py", line 7019, in editQualifier
      data = req.submit()
    File ".../core/pywikibot/data/api.py", line 2178, in submit
      raise APIError(**result['error'])
    pywikibot.data.api.APIError: invalid-snak: Invalid snak (Value must match 
the pattern for decimal values.) [messages:[{'parameters': [], 'name': 
'wikibase-api-invalid-snak', 'html': {'*': 'Invalid snak'}}]; help:See 
https://www.wikidata.org/w/api.php for API usage]
  
  I have modified the pywikibot code to format the quantity values as 
"+0.0000000019" rather than "+1.9e-09" and it goes through just fine. That is 
one solution, but it would probably better for the API to handle scientific 
notation properly as this will come up with any client that tries to provide 
very small (or large) values as quantities.

TASK DETAIL
  https://phabricator.wikimedia.org/T119226

EMAIL PREFERENCES
  https://phabricator.wikimedia.org/settings/panel/emailpreferences/

To: ArthurPSmith
Cc: Aklapper, StudiesWorld, pywikibot-bugs-list, ArthurPSmith, Wikidata-bugs, 
aude, Ricordisamoa, Mbch331, jayvdb



_______________________________________________
pywikibot-bugs mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/pywikibot-bugs

Reply via email to