Page MenuHomePhabricator

Unable to submit any pywikibot.WbTime with hour/minute/second even if precision is day or lower
Open, Stalled, MediumPublicBUG REPORT

Description

Steps to replicate the issue (include links if applicable):

site = pywikibot.Site("wikidata", "wikidata")
item = pywikibot.ItemPage(site, "Q4115189")
claim = pywikibot.Claim(site, "P580")
claim.setTarget(pywikibot.WbTime(year=2022, hour=5, precision=11))
item.addClaim(claim)

What happens?:

WARNING: API error modification-failed: Malformed input: +2022-01-01T05:00:00Z
---------------------------------------------------------------------------
APIError                                  Traceback (most recent call last)
File /srv/paws/pwb/pywikibot/page/_decorators.py:34, in _allow_asynchronous.<locals>.handle(func, self, *args, **kwargs)
     33 try:
---> 34     func(self, *args, **kwargs)
     35 # TODO: other "expected" error types to catch?

File /srv/paws/pwb/pywikibot/page/_wikibase.py:740, in WikibasePage.addClaim(self, claim, bot, **kwargs)
    738     raise ValueError(
    739         'The provided Claim instance is already used in an entity')
--> 740 self.repo.addClaim(self, claim, bot=bot, **kwargs)
    741 claim.on_item = self

File /srv/paws/pwb/pywikibot/site/_decorators.py:92, in need_right.<locals>.decorator.<locals>.callee(self, *args, **kwargs)
     89     raise UserRightsError('User "{}" does not have required '
     90                           'user right "{}"'
     91                           .format(self.user(), right))
---> 92 return fn(self, *args, **kwargs)

File /srv/paws/pwb/pywikibot/site/_datasite.py:324, in DataSite.addClaim(self, entity, claim, bot, summary)
    323 req = self.simple_request(**params)
--> 324 data = req.submit()
    325 # Update the item

File /srv/paws/pwb/pywikibot/data/api/_requests.py:1108, in Request.submit(self)
   1106     pywikibot.log('           response=\n{}'.format(result))
-> 1108     raise pywikibot.exceptions.APIError(**error)
   1109 except TypeError:

APIError: modification-failed: Malformed input: +2022-01-01T05:00:00Z
[messages: [{'name': 'wikibase-validator-malformed-value', 'parameters': ['+2022-01-01T05:00:00Z'], 'html': {'*': 'Malformed input: +2022-01-01T05:00:00Z'}}];
 servedby: mw1402;
 help: See https://www.wikidata.org/w/api.php for API usage. Subscribe to the mediawiki-api-announce mailing list at &lt;https://lists.wikimedia.org/postorius/lists/mediawiki-api-announce.lists.wikimedia.org/&gt; for notice of API deprecations and breaking changes.]

During handling of the above exception, another exception occurred:

OtherPageSaveError                        Traceback (most recent call last)
Cell In[24], line 1
----> 1 item.addClaim(claim)

File /srv/paws/pwb/pywikibot/page/_decorators.py:55, in _allow_asynchronous.<locals>.wrapper(self, *args, **kwargs)
     53     pywikibot.async_request(handle, func, self, *args, **kwargs)
     54 else:
---> 55     handle(func, self, *args, **kwargs)

File /srv/paws/pwb/pywikibot/page/_decorators.py:47, in _allow_asynchronous.<locals>.handle(func, self, *args, **kwargs)
     45         if isinstance(err, PageSaveRelatedError):
     46             raise err
---> 47         raise OtherPageSaveError(self, err)
     48 if callback:
     49     callback(self, err)

OtherPageSaveError: Edit to page [[wikidata:Q4115189]] failed:
modification-failed: Malformed input: +2022-01-01T05:00:00Z
[messages: [{'name': 'wikibase-validator-malformed-value', 'parameters': ['+2022-01-01T05:00:00Z'], 'html': {'*': 'Malformed input: +2022-01-01T05:00:00Z'}}];
 servedby: mw1402;
 help: See https://www.wikidata.org/w/api.php for API usage. Subscribe to the mediawiki-api-announce mailing list at &lt;https://lists.wikimedia.org/postorius/lists/mediawiki-api-announce.lists.wikimedia.org/&gt; for notice of API deprecations and breaking changes.]

What should have happened instead?: The time should be accepted.

Software version (skip for WMF-hosted wikis like Wikipedia):

Other information (browser name/version, screenshots, etc.): This makes making a WbTime via fromTimestamp() impossible because it copies everything including hours, minutes and seconds even when a precision of day or lower is given.

Event Timeline

RPI2026F1 changed the task status from Open to Stalled.Dec 23 2022, 1:49 AM
RPI2026F1 claimed this task.
RPI2026F1 triaged this task as Medium priority.

This can be easily fixed by normalizing the WbTime object whenever it's assigned to a claim. However, it means that the WbTime that's in the claim is no longer the same WbTime instance outside, so you couldn't modify the WbTime and have the changes propagate to the internal WbTime without setting it again.

RPI2026F1 changed the task status from Stalled to In Progress.Dec 28 2022, 3:32 AM

Change 872504 had a related patch set uploaded (by RPI2026F1; author: RPI2026F1):

[pywikibot/core@master] [Bugfix] Normalize WbTimes sent to Wikidata

https://gerrit.wikimedia.org/r/872504

Change 872504 merged by jenkins-bot:

[pywikibot/core@master] [Bugfix] Normalize WbTimes sent to Wikidata

https://gerrit.wikimedia.org/r/872504

Xqt reopened this task as Open.EditedJul 2 2023, 4:37 PM
Xqt subscribed.

This was due to T340495. The underlying issue can be found in T57755.

Change 934708 had a related patch set uploaded (by Xqt; author: Xqt):

[pywikibot/core@master] Revert "[Bugfix] Normalize WbTimes sent to Wikidata"

https://gerrit.wikimedia.org/r/934708

Xqt changed the task status from Open to Stalled.Jul 2 2023, 6:03 PM

Stalled due to T57755.

Change 934708 merged by jenkins-bot:

[pywikibot/core@master] Revert "[Bugfix] Normalize WbTimes sent to Wikidata"

https://gerrit.wikimedia.org/r/934708

Xqt removed RPI2026F1 as the assignee of this task.EditedDec 19 2023, 3:27 PM

The reason of revert is described in T340495, the underlying issue can be found in T57755

Change #655524 had a related patch set uploaded (by Xqt; author: Xqt):

[pywikibot/core@master] [tests] Add two edit tests for WbTime

https://gerrit.wikimedia.org/r/655524

Change #655524 merged by jenkins-bot:

[pywikibot/core@master] [tests] Add two edit tests for WbTime

https://gerrit.wikimedia.org/r/655524