Page MenuHomePhabricator

Incorrect server time from pywitibot
Closed, ResolvedPublicBUG REPORT

Description

Steps to Reproduce:

[03:16:58]tools.jjmc89-bot@tools-sgebastion-08:~> date -Iseconds
2020-10-21T03:16:59+00:00
[03:16:59]tools.jjmc89-bot@tools-sgebastion-08:~> python3
Python 3.5.3 (default, Jul  9 2020, 13:00:10)
[GCC 6.3.0 20170516] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import datetime, pywikibot
>>> datetime.datetime.utcnow()
datetime.datetime(2020, 10, 21, 3, 17, 35, 314456)
>>> datetime.datetime.now()
datetime.datetime(2020, 10, 21, 3, 17, 38, 927904)
>>> site = pywikibot.Site('commons', 'commons')
>>> site.server_time()

Actual Results:
Timestamp(2020, 10, 20, 7, 7, 8)

Expected Results:
Timestamp(2020, 10, 21, 3, 17, 40) (approximate)

Version:

Pywikibot: [https] r-pywikibot-core.git (5ebba28, g1, 2020/10/19, 16:57:22, stable)
Release version: 5.0.0
requests version: 2.21.0
  cacerts: /etc/ssl/certs/ca-certificates.crt
    certificate test: ok
Python: 3.5.3 (default, Jul  9 2020, 13:00:10)
[GCC 6.3.0 20170516]
Toolforge hostname: tools-sgebastion-08

Event Timeline

It looks like some caching issue since clearing the API cache resolved it temporarily before becoming stuck at a new time - the time it was first called after clearing the API cache.

The problem is that with expiry=True in self.siteinfo.get('time', expiry=True)
a CachedRequest is called and there True is converted to 1 day

def _request(self, **kwargs):
    """Create a request by forwarding all parameters directly."""
    if 'expiry' in kwargs and kwargs['expiry'] is None:
        del kwargs['expiry']

    return self._request_class(kwargs)(site=self, **kwargs)  --> this creates a CachedRequest with expiry=True, which will become 1 day

Change 635511 had a related patch set uploaded (by Mpaa; owner: Mpaa):
[pywikibot/core@master] [bugfix] do not allow that expiry=True is passed to a CachedRequest()

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

Change 635511 merged by jenkins-bot:
[pywikibot/core@master] [bugfix] convert expiry=True to expiry=0 in siteinfo.get()

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

JJMC89 assigned this task to Mpaa.