XZise added a comment.

The wiki supports to define the timestamp 
<https://test.wikipedia.org/w/api.php?action=help&modules=edit> of the latest 
revision in the edit so it can detect it. And we in theory apply that (see 
`APISite.editpage`) but only if the actual base revision is cached. Otherwise 
it might load the latest revision directly before the save which of course 
defeats the purpose as there won't be a conflict with the latest revision if 
it's loaded almost immediately before saving it.

So it requests the latests revision in `editpage`:

  […]
  if basetimestamp or not recreate:
      try:
          lastrev = page.latest_revision
          basetimestamp = lastrev.timestamp
      except NoPage:
          basetimestamp = False
          if not recreate:
              raise
  […]

And the method in the `Page` class:

  @property
  def latest_revision(self):
      """Return the current revision for this page."""
      rev = self._latest_cached_revision()
      if rev is not None:
          return rev
      return next(self.revisions(content=True, total=1))

And that is using `_latest_cached_revision` which is valid when using the 
PreloadingGenerator:

  >>> from pywikibot.pagegenerators import PreloadingGenerator as P
  >>> import pywikibot as py
  >>> s = py.Site()
  >>> p = py.Page(s, 'Main Page')
  >>> pp = list(P([p]))[0]
  Retrieving 1 pages from wikipedia:test.
  >>> pp._latest_cached_revision() is None
  False


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

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

To: XZise
Cc: XZise, jayvdb, Aklapper, pywikibot-bugs-list, Beta16



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

Reply via email to