Page MenuHomePhabricator

Site.server_time sometimes returns a wrong timestamp on the first call.
Closed, ResolvedPublic

Description

Run the following script:

from pywikibot import *
from time import *
s = Site('en', 'wikipedia')
print(s.server_time())
sleep(2)
print(s.server_time())
sleep(2)
print(s.server_time())

Result:

2018-08-18T11:23:28Z
2018-08-19T11:03:03Z
2018-08-19T11:03:06Z

Second and third timestamps make sense, but the first one should only be a few seconds earlier. It seems that the cached result is being returned for the first call by mistake.

Event Timeline

I think the root cause of the issue is that sometimes the general SiteInfo is loaded using a CachedRequest from a cache file, but gets a new timestamp.

We should change Siteinfo class to make it not update timestamps when loading from a CachedRequest or update it with a correct timestamp. Therefore, we may need to change CachedRequest and related calls somehow to return the the cache time to SiteInfo.

Dalba renamed this task from Site.server_time caches the results and returns wrong results in the next call. to Site.server_time sometimes returns a wrong timestamp on the first call..Aug 20 2018, 5:20 AM

Change 453944 had a related patch set uploaded (by Dalba; owner: dalba):
[pywikibot/core@master] Cleanup the code in site.SiteInfo

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

Change 453944 merged by jenkins-bot:
[pywikibot/core@master] pywikibot.site.Siteinfo: Fix the bug in cache_time when loading a CachedRequest

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