https://bugzilla.wikimedia.org/show_bug.cgi?id=72120
Bug ID: 72120 Summary: pagegenerators.GeneratorFactory() uses default site, even when command line args havent been processed Product: Pywikibot Version: core (2.0) Hardware: All OS: All Status: NEW Severity: major Priority: Unprioritized Component: General Assignee: Pywikipedia-bugs@lists.wikimedia.org Reporter: jayvdb@gmail.com Web browser: --- Mobile Platform: ---
In the current code, pywikibot.handleArgs() must be called before pagegenerators.GeneratorFactory(), as pagegenerators.GeneratorFactory.__init__() calls pywikibot.Site().
If pagegenerators.GeneratorFactory() is called first, the default site per user-config is used, and command line args (-family -lang -user) are ignored. See bug 63800.
This could be almost completely fixed by changing GeneratorFactory.site to be a property, loaded on access. That prevents the typical coding bug which look like:
genFactory = pagegenerators.GeneratorFactory() for arg in pywikibot.handleArgs(): if genFactory.handleArg(arg): pass
The current solution is to use and promote the pattern:
local_args = pywikibot.handleArgs() genFactory = pagegenerators.GeneratorFactory() for arg in local_args: if genFactory.handleArg(arg): pass
However it doesnt prevent this:
genFactory = pagegenerators.GeneratorFactory() genFactory.handleArg('-file:' + filename): ... pywikibot.handleArgs()
One way to prevent that is to raise an exception in pywikibot.handleArgs if it is called after pywikibot.Site() has instantiated a default site, and possibly only if -family/-lang/-user are supplied on the command line.
Another approach (very dodgy) is for pywikibot to know which Site object is the 'default' site, and pywikibot.handleArgs() change that object if -family/-lang/-user are supplied on the command line.
https://bugzilla.wikimedia.org/show_bug.cgi?id=72120
John Mark Vandenberg jayvdb@gmail.com changed:
What |Removed |Added ---------------------------------------------------------------------------- Priority|Unprioritized |Normal CC| |CommodoreFabianus@gmx.de See Also| |https://bugzilla.wikimedia. | |org/show_bug.cgi?id=63800 Blocks| |72118 Summary|pagegenerators.GeneratorFac |pagegenerators.GeneratorFac |tory() uses default site, |tory() uses wrong site if |even when command line args |instantiated before command |havent been processed |line args have been | |processed
--- Comment #1 from John Mark Vandenberg jayvdb@gmail.com --- Enforcing the order of initialisation by adding an exception in pywikibot.handle_args() (previously: handleArgs) or in GeneratorFactory.__init__() would need to be post 2.0
https://bugzilla.wikimedia.org/show_bug.cgi?id=72120
--- Comment #2 from John Mark Vandenberg jayvdb@gmail.com --- A better pattern to use and promote is:
local_args = pywikibot.handleArgs() site = pywikibot.Site() genFactory = pagegenerators.GeneratorFactory(site) for arg in local_args: if genFactory.handleArg(arg): pass ...
As that shows the fact that genFactory needs a site object.
https://bugzilla.wikimedia.org/show_bug.cgi?id=72120
--- Comment #3 from Gerrit Notification Bot gerritadmin@wikimedia.org --- Change 166942 had a related patch set uploaded by John Vandenberg: Use correct site for pagegenerators
https://gerrit.wikimedia.org/r/166942
https://bugzilla.wikimedia.org/show_bug.cgi?id=72120
Gerrit Notification Bot gerritadmin@wikimedia.org changed:
What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |PATCH_TO_REVIEW
https://bugzilla.wikimedia.org/show_bug.cgi?id=72120
--- Comment #4 from Gerrit Notification Bot gerritadmin@wikimedia.org --- Change 166942 merged by jenkins-bot: Use correct site for pagegenerators
https://gerrit.wikimedia.org/r/166942
https://bugzilla.wikimedia.org/show_bug.cgi?id=72120
John Mark Vandenberg jayvdb@gmail.com changed:
What |Removed |Added ---------------------------------------------------------------------------- Status|PATCH_TO_REVIEW |NEW
--- Comment #5 from John Mark Vandenberg jayvdb@gmail.com --- The last patch is almost a 100% solution, but it doesnt ensure pywikibot.Site() is only being called after handle_args.
https://bugzilla.wikimedia.org/show_bug.cgi?id=72120
John Mark Vandenberg jayvdb@gmail.com changed:
What |Removed |Added ---------------------------------------------------------------------------- Severity|major |minor
pywikipedia-bugs@lists.wikimedia.org