|
| 1 | +#!/usr/bin/env python |
| 2 | +# |
| 3 | +# This work is licensed under the GNU GPLv2 or later. |
| 4 | +# See the COPYING file in the top-level directory. |
| 5 | + |
| 6 | +# redhat_query_all.py: Perform a few varieties of queries |
| 7 | + |
| 8 | +import bugzilla |
| 9 | + |
| 10 | +# public test instance of bugzilla.redhat.com. It's okay to make changes |
| 11 | +URL = "bugzilla.stage.redhat.com" |
| 12 | + |
| 13 | +bzapi = bugzilla.Bugzilla(URL) |
| 14 | + |
| 15 | + |
| 16 | +# In late 2021, bugzilla.redhat.com changed query() results to default to |
| 17 | +# returning only 20 bugs. If the user passes in limit=0, that number changes |
| 18 | +# to 1000, but is still capped if the query would return more than that. |
| 19 | +# |
| 20 | +# There's a discussion here with multiple proposed ways to work around it: |
| 21 | +# https://github.com/python-bugzilla/python-bugzilla/issues/149 |
| 22 | +# |
| 23 | +# This method uses ids_only=True, which is a custom bugzilla.redhat.com |
| 24 | +# query feature to bypass the query limit by only returning matching bug IDs. |
| 25 | +# rhbz feature bug: https://bugzilla.redhat.com/show_bug.cgi?id=2005153 |
| 26 | + |
| 27 | + |
| 28 | +# As of Feb 2024 this 1300+ bugs, which would have hit the query limit of 1000 |
| 29 | +query = bzapi.build_query( |
| 30 | + product="Fedora", |
| 31 | + component="virt-manager") |
| 32 | +# Request the bugzilla.redhat.com extension ids_only=True to bypass limit |
| 33 | +query["ids_only"] = True |
| 34 | + |
| 35 | +queried_bugs = bzapi.query(query) |
| 36 | +ids = [bug.id for bug in queried_bugs] |
| 37 | +print(f"Queried {len(ids)} ids") |
| 38 | + |
| 39 | + |
| 40 | +# Use getbugs to fetch the full list. getbugs is not affected by |
| 41 | +# default RHBZ limits. However, requesting too much data via getbugs |
| 42 | +# will timeout. This paginates the lookup to query 1000 bugs at a time. |
| 43 | +# |
| 44 | +# We also limit the returned data to just give us the `summary`. |
| 45 | +# You should always limit your queries with include_fields` to only return |
| 46 | +# the data you need. |
| 47 | +count = 0 |
| 48 | +pagesize = 1000 |
| 49 | +include_fields = ["summary"] |
| 50 | +while count < len(ids): |
| 51 | + idslice = ids[count:(count + pagesize)] |
| 52 | + print(f"Fetching data for bugs {count}-{count+len(idslice)-1}") |
| 53 | + bugs = bzapi.getbugs(idslice, include_fields=include_fields) |
| 54 | + print(f"Fetched {len(bugs)} bugs") |
| 55 | + count += pagesize |
0 commit comments