From de82e7860ae7a1a6f9876b6aae92cb5df09c6008 Mon Sep 17 00:00:00 2001 From: Tim Flink Date: Sep 15 2021 12:37:30 +0000 Subject: bz_interface: hotfix for Bugzilla returning only 20 results per request Bugzilla suddenly changed its query limit to 20 bugs, which means our queries returned incomplete. --- diff --git a/blockerbugs.spec b/blockerbugs.spec index 1023cdf..94b143f 100644 --- a/blockerbugs.spec +++ b/blockerbugs.spec @@ -1,7 +1,7 @@ Name: blockerbugs # NOTE: if you update version, *make sure* to also update # `blockerbugs/__init__.py` and `docs/source/conf.py` -Version: 1.4.0 +Version: 1.4.1 Release: 1%{?dist} Summary: Fedora QA Blocker Tracking Application @@ -108,6 +108,9 @@ cp -v docs/_build/man/*.1 %{buildroot}/%{_mandir}/man1/ %changelog +* Mon Sep 13 2021 Tim Flink - 1.4.1-1 +- hotfix to address change to rhbz and the number of results returned + * Mon Aug 23 2021 Frantisek Zatloukal - 1.4.0-1 - SQLAlchemy: add naming conventions - replace partner-bugzilla with bugzilla.stage diff --git a/blockerbugs/util/bz_interface.py b/blockerbugs/util/bz_interface.py index 471140f..44a7812 100644 --- a/blockerbugs/util/bz_interface.py +++ b/blockerbugs/util/bz_interface.py @@ -29,10 +29,14 @@ from xmlrpc.client import Fault from blockerbugs import app +# anonymous users can now query for at most 20 results at a time +BUGZILLA_QUERY_LIMIT = 20 + base_query = {'o1': 'anywords', 'f1': 'blocked', 'query_format': 'advanced', - 'extra_fields': ['flags']} + 'extra_fields': ['flags'], + 'limit': BUGZILLA_QUERY_LIMIT} class BZInterfaceError(Exception): @@ -77,12 +81,14 @@ class BlockerBugs(): # https://bugzilla.stage.redhat.com/buglist.cgi?bug_status=NEW&bug_status=ASSIGNED # &bug_status=POST&bug_status=MODIFIED&classification=Fedora&component=anaconda&f1=component # &o1=changedafter&product=Fedora&query_format=advanced&v1=2013-03-21%2012%3A25&version=19 - def get_bz_query(self, tracker: int, last_update: datetime.datetime = None) -> dict[str, Any]: + def get_bz_query(self, tracker: int, last_update: datetime.datetime = None, offset: int = 0 + ) -> dict[str, Any]: """Build a Bugzilla query to retrieve all necessary info about all bugs which block the `tracker` bug. :param last_update: If provided, the query is modified to ask only about bugs which have recent modifications; otherwise asks about all bugs. + :offset: offset to the query instead of just getting the first N results :returns: a dict which can be fed into `bugzilla.Bugzilla.query()`. """ query = {} @@ -129,6 +135,9 @@ class BlockerBugs(): 'f10': 'CP' }) + # update query with the offset to use, no change in behavior if the default 0 is used + query.update({'offset': offset}) + return query def query_tracker(self, tracker: int, last_update: Optional[datetime.datetime] = None @@ -139,12 +148,26 @@ class BlockerBugs(): :param last_update: If provided, the query is modified to ask only about bugs which have recent modifications; otherwise asks about all bugs. """ - query = self.get_bz_query(tracker, last_update) - buglist = self.bz.query(query) + + buglist: list[bzBug] = [] + last_query_len = BUGZILLA_QUERY_LIMIT + + # FIXME: this is a hotfix hack to work around the sudden config change in rhbz where the max + # number of bugs returned for a query is 20 + # it seems to be working for now but may need more work going forward + while last_query_len == BUGZILLA_QUERY_LIMIT: + + new_query = self.get_bz_query(tracker, last_update, offset=len(buglist)) + new_buglist = self.bz.query(new_query) + buglist.extend(new_buglist) + last_query_len = len(new_buglist) + return buglist def query_prioritized(self) -> list[bzBug]: """Perform a Bugzilla query and retrieve all necessary info about all Prioritized bugs.""" + # FIXME: implement pagination support + # https://bugzilla.redhat.com/buglist.cgi?bug_status=__open__& # f1=flagtypes.name&o1=substring&query_format=advanced&v1=fedora_prioritized_bug%2B query = self.bz.url_to_query(