I want to get the contents of a page and a list of all the revisions up to that point in time. If I do:
text = page.get() revisions = list(page.revisions())
I assume there's a race condition there, in that a new revision could be written after the get() is executed. Is there any (hopefully eash) way to avoid that?
On Thu, Mar 19, 2026 at 10:24 PM Roy Smith via pywikibot pywikibot@lists.wikimedia.org wrote:
I want to get the contents of a page and a list of all the revisions up to that point in time. If I do:
text = page.get() revisions = list(page.revisions())I assume there's a race condition there, in that a new revision could be written after the get() is executed. Is there any (hopefully eash) way to avoid that?
If you do the calls in that order, can't you just prune the revision history to exclude any revisions that were written in the N msec since you fetched the page (if there are any)?
Tom
În vin., 20 mar. 2026 la 04:24, Roy Smith via pywikibot < pywikibot@lists.wikimedia.org> a scris:
I want to get the contents of a page and a list of all the revisions up to that point in time. If I do:
text = page.get() revisions = list(page.revisions())
Hi,
I haven't tested this, but I don't think you need to do get(). You can try something like
``` page = pywikibot.Page(site, title) revisions = list(page.revisions(content=True)) text = revisions[0].text ```
The only downside is that it loads the content from all revisions.
HTH, Strainu
I assume there's a race condition there, in that a new revision could be written after the get() is executed. Is there any (hopefully eash) way to avoid that? _______________________________________________ pywikibot mailing list -- pywikibot@lists.wikimedia.org Public archives at https://lists.wikimedia.org/hyperkitty/list/pywikibot@lists.wikimedia.org/me... To unsubscribe send an email to pywikibot-leave@lists.wikimedia.org
Ah, interesting, thanks. It looks like what I'll end up doing is:
revisions = list(page.revisions()) last_timestamp = revisions[0]["timestamp"] last_rev = list(page.revisions(total=1, starttime=last_timestamp, content=True))
i.e. make two calls to revisions(): the first gets all the metadata, the second gets the content for the newest revision as of the time of the first call.
And, just to save folks from going down the same rabbit hole I went down, if you do:
page.get() revisions = list(page.revisions(content=False))
It looks like the revisions() call discovers that it already has the content for one revision in cache and inserts that into that specific Revision object, despite content=False. I don't know if that's a bug or not, but it's certainly surprising https://en.wikipedia.org/wiki/Principle_of_least_astonishment. I was on the verge of opening a "Page.revisions ignores contents argument" bug when I figured out what was going on.
On Mar 20, 2026, at 4:44 AM, Strainu via pywikibot pywikibot@lists.wikimedia.org wrote:
În vin., 20 mar. 2026 la 04:24, Roy Smith via pywikibot <pywikibot@lists.wikimedia.org mailto:pywikibot@lists.wikimedia.org> a scris:
I want to get the contents of a page and a list of all the revisions up to that point in time. If I do:
text = page.get() revisions = list(page.revisions())Hi,
I haven't tested this, but I don't think you need to do get(). You can try something like
page = pywikibot.Page(site, title) revisions = list(page.revisions(content=True)) text = revisions[0].textThe only downside is that it loads the content from all revisions.
HTH, Strainu
I assume there's a race condition there, in that a new revision could be written after the get() is executed. Is there any (hopefully eash) way to avoid that? _______________________________________________ pywikibot mailing list -- pywikibot@lists.wikimedia.org mailto:pywikibot@lists.wikimedia.org Public archives at https://lists.wikimedia.org/hyperkitty/list/pywikibot@lists.wikimedia.org/me... To unsubscribe send an email to pywikibot-leave@lists.wikimedia.org mailto:pywikibot-leave@lists.wikimedia.org
pywikibot mailing list -- pywikibot@lists.wikimedia.org Public archives at https://lists.wikimedia.org/hyperkitty/list/pywikibot@lists.wikimedia.org/me... To unsubscribe send an email to pywikibot-leave@lists.wikimedia.org