Demonstrated on listpages.py.
page_target.text = text page_target.save(summary=summary)
- Page.text.setter updates the Page._text attribute with the new content
- Page.save calls Page._save internally
- Page._save calls Page._cosmetic_changes_hook
- Page._cosmetic_changes_hook calls Page.content_model (new after rPWBC94a3f39a038a87e7516e55a253423609694d5342)
- Page.content_model cannot use cached information because it hasn't been loaded yet (when -overwrite is used), so it calls APISite.loadpageinfo -> APISite._update_page -> pywikibot.data.api.update_page
- pywikibot.data.api.update_page does del page.text which unconditionally deletes Page._text (the text saved in page_target.text = text)
The last step is the problem: APISite.loadpageinfo deletes the useful content.
Workarounds:
- (for users) disable cosmetic changes
- (for developers) always completely initialize the page object before updating its content
Quick fix: revert rPWBC94a3f39a038a87e7516e55a253423609694d5342 (or just remove the content_model check).