Page MenuHomePhabricator

Content parameter in page.template() has no effect if page templates are cached
Closed, ResolvedPublicBUG REPORT

Description

When page templates are already cached, content parameter has no effect.

page._templates might be created also when page is preloaded, with templates=True.

Steps to replicate the issue (include links if applicable):

>>> site = pywikibot.Site('en', 'wikisource')
>>> page = pywikibot.Page(site, 'Main Page')

>>> tt = page.templates()
>>> vars(tt[-1])
{'_link': pywikibot.page.Link('Yesno', APISite("en", "wikisource")),
 '_revisions': {},
 '_pageid': 1596012,
 '_contentmodel': 'Scribunto',
 '_isredir': False,
 '_timestamp': '2022-07-25T08:55:24Z',
 '_applicable_protections': {'edit', 'move'},
 '_protection': {'edit': ('sysop', 'infinity'), 'move': ('sysop', 'infinity')},
 '_revid': 11131966}


>>> tt = page.templates(content=True)
>>> vars(tt[-1])
{'_link': pywikibot.page.Link('Yesno', APISite("en", "wikisource")),
 '_revisions': {},
 '_pageid': 1596012,
 '_contentmodel': 'Scribunto',
 '_isredir': False,
 '_timestamp': '2022-07-25T08:55:24Z',
 '_applicable_protections': {'edit', 'move'},
 '_protection': {'edit': ('sysop', 'infinity'), 'move': ('sysop', 'infinity')},
 '_revid': 11131966}


>>> del page._templates
>>> tt = page.templates(content=True)
>>> vars(tt[-1])
{'_link': pywikibot.page.Link('Yesno', APISite("en", "wikisource")),
 '_revisions': {11131966: Revision({'revid': 11131966, 'parentid': 10475162, 'minor': True, 'user': 'Xover', 'timestamp': Timestamp(2021, 3, 26, 18, 44, 37), 'slots': {'main': {'contentmodel': 'Scribunto', 'contentformat': 'text/plain', '*': '-- Function allowing for consistent treatment of boolean-like wikitext input.\n-- It works similarly to the template {{yesno}}.\n\nreturn function (val, default)\n\t-- If your wiki uses non-ascii characters for any of "yes", "no", etc., you\n\t-- should replace "val:lower()" with "mw.ustring.lower(val)" in the\n\t-- following line.\n\tval = type(val) == \'string\' and val:lower() or val\n\tif val == nil then\n\t\treturn nil\n\telseif val == true \n\t\tor val == \'yes\'\n\t\tor val == \'y\'\n\t\tor val == \'true\'\n\t\tor val == \'t\'\n\t\tor val == \'on\'\n\t\tor tonumber(val) == 1\n\tthen\n\t\treturn true\n\telseif val == false\n\t\tor val == \'no\'\n\t\tor val == \'n\'\n\t\tor val == \'false\'\n\t\tor val == \'f\'\n\t\tor val == \'off\'\n\t\tor tonumber(val) == 0\n\tthen\n\t\treturn false\n\telse\n\t\treturn default\n\tend\nend'}}, 'comment': 'Protected "[[Module:Yesno]]": Core module which should only be changed through import from its upstream at enwp. ([Edit=Allow only administrators] (indefinite) [Move=Allow only administrators] (indefinite))', 'anon': False, 'userhidden': False, 'commenthidden': False, 'text': '-- Function allowing for consistent treatment of boolean-like wikitext input.\n-- It works similarly to the template {{yesno}}.\n\nreturn function (val, default)\n\t-- If your wiki uses non-ascii characters for any of "yes", "no", etc., you\n\t-- should replace "val:lower()" with "mw.ustring.lower(val)" in the\n\t-- following line.\n\tval = type(val) == \'string\' and val:lower() or val\n\tif val == nil then\n\t\treturn nil\n\telseif val == true \n\t\tor val == \'yes\'\n\t\tor val == \'y\'\n\t\tor val == \'true\'\n\t\tor val == \'t\'\n\t\tor val == \'on\'\n\t\tor tonumber(val) == 1\n\tthen\n\t\treturn true\n\telseif val == false\n\t\tor val == \'no\'\n\t\tor val == \'n\'\n\t\tor val == \'false\'\n\t\tor val == \'f\'\n\t\tor val == \'off\'\n\t\tor tonumber(val) == 0\n\tthen\n\t\treturn false\n\telse\n\t\treturn default\n\tend\nend', 'contentmodel': 'Scribunto', 'sha1': 'f767643e7d12126d020d88d662a3dd057817b9dc'})},
 '_pageid': 1596012,
 '_contentmodel': 'Scribunto',
 '_isredir': False,
 '_timestamp': '2022-07-25T08:55:24Z',
 '_applicable_protections': {'edit', 'move'},
 '_protection': {'edit': ('sysop', 'infinity'), 'move': ('sysop', 'infinity')},
 '_revid': 11131966}

What happens?:
Content is not loaded.

What should have happened instead?:
Content should be loaded.

Software version (skip for WMF-hosted wikis like Wikipedia):
pywikibot-core.git (9be8e5b, g16828, 2022/07/24, 12:35:36, OUTDATED)

Event Timeline

Mpaa renamed this task from Content parameter has no effect if page templates are cached to Content parameter in page.template() has no effect if page templates are cached.Jul 25 2022, 3:01 PM
Mpaa updated the task description. (Show Details)

Change 816853 had a related patch set uploaded (by Mpaa; author: Mpaa):

[pywikibot/core@master] [bugfix] Fix content=True in page.template()

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

Xqt triaged this task as High priority.

Change 816853 merged by jenkins-bot:

[pywikibot/core@master] [bugfix] Fix content=True in page.template()

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