Page MenuHomePhabricator

Frames aren't available outside of functions in modules
Closed, ResolvedPublic

Description

Create the following as Module:Foo:

local p = {}

local f = mw.getCurrentFrame()

function p.main(frame)
return 'The title of the current frame is ' .. f:getTitle()
end

return p

When {{#invoke:Foo|main}} is used in a page, a script error will be generated because f is nil. Note the bug is not present in the console, where running =p.main() will produce the expected result.

Also, if the following is created as Module:Bar:

local p = {}

local d = os.date()

function p.main(frame)
return 'The date when the module was ran was ' .. d
end

return p

{{#invoke:Bar|main}} will return a script error because the TTL logic in os.date() assumes that frames are available at this point, when in fact they are not. Again, this only malfunctions when called from wikitext; =p.main() works properly from the console.


Version: unspecified
Severity: normal

Details

Reference
bz67498

Event Timeline

bzimport raised the priority of this task from to Needs Triage.Nov 22 2014, 3:32 AM
bzimport added a project: Scribunto.
bzimport set Reference to bz67498.

Change 144478 had a related patch set uploaded by Anomie:
Improve mw.getCurrentFrame handling

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

Change 144478 merged by jenkins-bot:
Improve mw.getCurrentFrame handling

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

Change 144511 had a related patch set uploaded by Jackmcbarn:
Improve mw.getCurrentFrame handling

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

Change 144511 merged by jenkins-bot:
Improve mw.getCurrentFrame handling

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