Skip to content

IndexError raised in Bugzilla._getbug with REST backend #174

Description

@crazyscientist

Problem

When using/enforcing the use of the REST API, the _getbug method raises an IndexError, if

  1. the specified bug ID does not exist or
  2. the user is not authorized to access the bug

1. ID does not exist

>>> b = Bugzilla(url='https://bugzilla.redhat.com', force_rest=True)
>>> b.getbug(214525300)
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/usr/lib/python3.6/site-packages/bugzilla/base.py", line 1133, in getbug
    extra_fields=extra_fields)
  File "/usr/lib/python3.6/site-packages/bugzilla/base.py", line 1123, in _getbug
    return self._getbugs([objid], permissive=False, **kwargs)[0]
IndexError: list index out of range

2. Not authorized

>>> b = Bugzilla(url='https://bugzilla.redhat.com', force_rest=True)
>>> b.getbug(2145254)
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/usr/lib/python3.6/site-packages/bugzilla/base.py", line 1133, in getbug
    extra_fields=extra_fields)
  File "/usr/lib/python3.6/site-packages/bugzilla/base.py", line 1123, in _getbug
    return self._getbugs([objid], permissive=False, **kwargs)[0]
IndexError: list index out of range

Preliminary analysis

When using the API route /rest/bug/<bug_id> one would get appropriate answers from the API (i.e. error 404 and 401), but the _getbug method uses the /rest/bug endpoint instead with an ids argument containing a single ID. In this case the API returns an empty list, which seems to be the direct cause of the IndexError.

Comparison with XMLRPC

>>> b = Bugzilla(url='https://bugzilla.redhat.com')
>>> b.getbug(214525300)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/andi/virtualenvs/smash/lib/python3.10/site-packages/bugzilla/base.py", line 1129, in getbug
    data = self._getbug(objid,
  File "/home/andi/virtualenvs/smash/lib/python3.10/site-packages/bugzilla/base.py", line 1121, in _getbug
    return self._getbugs([objid], permissive=False, **kwargs)[0]
  File "/home/andi/virtualenvs/smash/lib/python3.10/site-packages/bugzilla/base.py", line 1094, in _getbugs
    r = self._backend.bug_get(ids, aliases, getbugdata)
  File "/home/andi/virtualenvs/smash/lib/python3.10/site-packages/bugzilla/_backendxmlrpc.py", line 179, in bug_get
    return self._xmlrpc_proxy.Bug.get(data)
  File "/usr/lib/python3.10/xmlrpc/client.py", line 1122, in __call__
    return self.__send(self.__name, args)
  File "/home/andi/virtualenvs/smash/lib/python3.10/site-packages/bugzilla/_backendxmlrpc.py", line 125, in _ServerProxy__request
    ret = ServerProxy._ServerProxy__request(
  File "/usr/lib/python3.10/xmlrpc/client.py", line 1464, in __request
    response = self.__transport.request(
  File "/home/andi/virtualenvs/smash/lib/python3.10/site-packages/bugzilla/_backendxmlrpc.py", line 100, in request
    return self.__request_helper(url, request_body)
  File "/home/andi/virtualenvs/smash/lib/python3.10/site-packages/bugzilla/_backendxmlrpc.py", line 47, in __request_helper
    return self.parse_response(response)
  File "/home/andi/virtualenvs/smash/lib/python3.10/site-packages/bugzilla/_backendxmlrpc.py", line 84, in parse_response
    return unmarshaller.close()
  File "/usr/lib/python3.10/xmlrpc/client.py", line 668, in close
    raise Fault(**self._stack[0])
xmlrpc.client.Fault: <Fault 101: 'Bug #214525300 does not exist.'>
>>> b.getbug(2145254)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/andi/virtualenvs/smash/lib/python3.10/site-packages/bugzilla/base.py", line 1129, in getbug
    data = self._getbug(objid,
  File "/home/andi/virtualenvs/smash/lib/python3.10/site-packages/bugzilla/base.py", line 1121, in _getbug
    return self._getbugs([objid], permissive=False, **kwargs)[0]
  File "/home/andi/virtualenvs/smash/lib/python3.10/site-packages/bugzilla/base.py", line 1094, in _getbugs
    r = self._backend.bug_get(ids, aliases, getbugdata)
  File "/home/andi/virtualenvs/smash/lib/python3.10/site-packages/bugzilla/_backendxmlrpc.py", line 179, in bug_get
    return self._xmlrpc_proxy.Bug.get(data)
  File "/usr/lib/python3.10/xmlrpc/client.py", line 1122, in __call__
    return self.__send(self.__name, args)
  File "/home/andi/virtualenvs/smash/lib/python3.10/site-packages/bugzilla/_backendxmlrpc.py", line 125, in _ServerProxy__request
    ret = ServerProxy._ServerProxy__request(
  File "/usr/lib/python3.10/xmlrpc/client.py", line 1464, in __request
    response = self.__transport.request(
  File "/home/andi/virtualenvs/smash/lib/python3.10/site-packages/bugzilla/_backendxmlrpc.py", line 100, in request
    return self.__request_helper(url, request_body)
  File "/home/andi/virtualenvs/smash/lib/python3.10/site-packages/bugzilla/_backendxmlrpc.py", line 47, in __request_helper
    return self.parse_response(response)
  File "/home/andi/virtualenvs/smash/lib/python3.10/site-packages/bugzilla/_backendxmlrpc.py", line 84, in parse_response
    return unmarshaller.close()
  File "/usr/lib/python3.10/xmlrpc/client.py", line 668, in close
    raise Fault(**self._stack[0])
xmlrpc.client.Fault: <Fault 102: 'You are not authorized to access bug #2145254. To see this bug, you must first log in to an account with the appropriate permissions.'>

Expected behavior

  • The REST backend should raise an exception similar to the XMLRPC backend.
  • The exception should contain all relevant information that allows meaningful exception handling outside of this client library.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions