jenkins-bot has submitted this change and it was merged.
Change subject: Deprecate ParamInfo.query_modules_with_limits ......................................................................
Deprecate ParamInfo.query_modules_with_limits
query_modules_with_limits is an unnecessary performance hit during site initialisation, and causes problems in production when there are problems with a query module.
It also causes a paraminfo caching bug to become a major bug preventing all access due to an assert added in 424eaa3.
Bug: T100779 Bug: T109168 Change-Id: I90910e52395f1db72f51088fa4306f62b625cc2c (cherry picked from commit 879defd1fd5ee7976d364fc34cd99254c31e4737) --- M pywikibot/data/api.py M tests/api_tests.py M tests/utils.py 3 files changed, 29 insertions(+), 8 deletions(-)
Approvals: Merlijn van Deen: Looks good to me, approved jenkins-bot: Verified
diff --git a/pywikibot/data/api.py b/pywikibot/data/api.py index 0d4d01e..c2af5ea 100644 --- a/pywikibot/data/api.py +++ b/pywikibot/data/api.py @@ -797,6 +797,7 @@ if self[mod][attribute])
@property + @deprecated('parameter()') def query_modules_with_limits(self): """Set of all query modules which have limits.""" if not self._with_limits: @@ -2059,10 +2060,11 @@ kwargs['continue'] = True self.request = Request(**kwargs)
- # This forces all paraminfo for all query modules to be bulk loaded. - limited_modules = ( - set(self.modules) & self.site._paraminfo.query_modules_with_limits - ) + self.site._paraminfo.fetch('query+' + mod for mod in self.modules) + + limited_modules = set( + mod for mod in self.modules + if self.site._paraminfo.parameter('query+' + mod, 'limit'))
if not limited_modules: self.limited_module = None @@ -2073,7 +2075,7 @@ # Query will continue as needed until limit (if any) for this module # is reached. for module in self.modules: - if module in self.site._paraminfo.query_modules_with_limits: + if module in limited_modules: self.limited_module = module limited_modules.remove(module) break diff --git a/tests/api_tests.py b/tests/api_tests.py index dde46f5..1facab9 100644 --- a/tests/api_tests.py +++ b/tests/api_tests.py @@ -276,6 +276,19 @@ self.assertIn('revisions', pi.prefixes)
+class TestParaminfoModules(DefaultSiteTestCase): + + """Test loading all paraminfo modules.""" + + def test_action_modules(self): + """Test loading all action modules.""" + self.site._paraminfo.fetch(self.site._paraminfo.action_modules) + + def test_query_modules(self): + """Test loading all query modules.""" + self.site._paraminfo.fetch(self.site._paraminfo.query_modules) + + class TestOptionSet(TestCase):
"""OptionSet class test class.""" diff --git a/tests/utils.py b/tests/utils.py index db2b9a3..5fef89e 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -116,14 +116,20 @@ self.prefixes = set()
def fetch(self, modules, _init=False): - """Prevented method.""" - raise Exception(u'DryParamInfo.fetch(%r, %r) prevented' - % (modules, _init)) + """Load dry data.""" + return [self[mod] for mod in modules]
def parameter(self, module, param_name): """Load dry data.""" return self[module][param_name]
+ def __getitem__(self, name): + """Return dry data or a dummy parameter block.""" + try: + return super(DryParamInfo, self).__getitem__(name) + except KeyError: + return {'name': name, 'limit': None} +
class DummySiteinfo():