jenkins-bot has submitted this change and it was merged.
Change subject: [FIX] ParamInfo: Correctly initialize ParamInfo ......................................................................
[FIX] ParamInfo: Correctly initialize ParamInfo
The ParamInfo can do some sanity checking but that is not possible when the base modules aren't loaded yet. The 424eaa35 change assumed that it would first add the main modules and then the query modules. But in certain cases it first added the query modules which let the class think it is properly initialized. This could only happen when it loads the query modules together with the main modules and even then could use the working ordering by chance.
Change-Id: I5fb97ba12acf7389c2ce37eff87e1aca432d397a --- M pywikibot/data/api.py M tests/api_tests.py 2 files changed, 29 insertions(+), 7 deletions(-)
Approvals: John Vandenberg: Looks good to me, approved jenkins-bot: Verified
diff --git a/pywikibot/data/api.py b/pywikibot/data/api.py index c50e46d..a7b7f6d 100644 --- a/pywikibot/data/api.py +++ b/pywikibot/data/api.py @@ -551,13 +551,15 @@ # query modules can be prefixed with 'query+' self._init()
- if 'query' in self._modules: - # It does fetch() while initializing, and this method can't be - # called before it's initialized. - modules = self._normalize_modules(modules) - elif self._action_modules: - # At least we do know the valid action modules and require a subset - assert not modules - self._action_modules - self.root_modules + if self._action_modules: + # The query module may be added before the action modules have been + if 'query' in self._modules: + # It does fetch() while initializing, and this method can't be + # called before it's initialized. + modules = self._normalize_modules(modules) + else: + # At least we do know the valid action modules and require a subset + assert not modules - self._action_modules - self.root_modules
self._fetch(modules)
diff --git a/tests/api_tests.py b/tests/api_tests.py index 213cf3b..2a76405 100644 --- a/tests/api_tests.py +++ b/tests/api_tests.py @@ -163,6 +163,26 @@ self.assertIn('info', pi.query_modules) self.assertIn('login', pi._action_modules)
+ def test_init_query_first(self): + """Test init where it first adds query and then main.""" + def patched_generate_submodules(modules): + # Change the query such that query is handled before main + modules = set(modules) + if 'main' in modules: + assert 'query' in modules + modules.discard('main') + modules = list(modules) + ['main'] + else: + assert 'query' not in modules + original_generate_submodules(modules) + pi = api.ParamInfo(self.site, set(['query', 'main'])) + self.assertEqual(len(pi), 0) + original_generate_submodules = pi._generate_submodules + pi._generate_submodules = patched_generate_submodules + pi._init() + self.assertIn('main', pi._paraminfo) + self.assertIn('query', pi._paraminfo) + def test_init_pageset(self): site = self.get_site() self.assertNotIn('query', api.ParamInfo.init_modules)