Skip to content

Commit 7b9df00

Browse files
committed
Bugzilla: Don't overwrite subclass with RHBugzilla
If a user subclasses Bugzilla, we don't want to overwrite __class__ with the RHBugzilla detection back compat Closes: #129 Signed-off-by: Cole Robinson <[email protected]>
1 parent 7aa70ed commit 7b9df00

2 files changed

Lines changed: 21 additions & 4 deletions

File tree

bugzilla/base.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -270,9 +270,15 @@ def _init_class_from_url(self):
270270
"""
271271
from .oldclasses import RHBugzilla # pylint: disable=cyclic-import
272272

273-
if self._detect_is_redhat_bugzilla():
273+
if not self._detect_is_redhat_bugzilla():
274+
return
275+
276+
self._is_redhat_bugzilla = True
277+
if self.__class__ == Bugzilla:
278+
# Overriding the class doesn't have any functional effect,
279+
# but we continue to do it for API back compat incase anyone
280+
# is doing any class comparison. We should drop this in the future
274281
self.__class__ = RHBugzilla
275-
self._is_redhat_bugzilla = True
276282

277283
def _get_field_aliases(self):
278284
# List of field aliases. Maps old style RHBZ parameter

tests/test_ro_functional.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,11 @@
1919
"https://bugzilla.redhat.com")
2020

2121

22-
def _open_bz(url, **kwargs):
22+
def _open_bz(url, bzclass=None, **kwargs):
2323
if "use_creds" not in kwargs:
2424
kwargs["use_creds"] = False
25-
return tests.utils.open_functional_bz(bugzilla.Bugzilla, url, kwargs)
25+
return tests.utils.open_functional_bz(bzclass or bugzilla.Bugzilla,
26+
url, kwargs)
2627

2728

2829
def _check(out, mincount, expectstr):
@@ -39,11 +40,21 @@ def _test_version(bz, bzversion):
3940
assert bz.bz_ver_minor == bzversion[1]
4041

4142

43+
def test_bugzilla_override():
44+
class MyBugzilla(bugzilla.Bugzilla):
45+
pass
46+
47+
bz = _open_bz("bugzilla.redhat.com", bzclass=MyBugzilla)
48+
assert bz.__class__ is MyBugzilla
49+
assert bz._is_redhat_bugzilla is True # pylint: disable=protected-access
50+
51+
4252
def test_rest_xmlrpc_detection():
4353
# The default: use XMLRPC
4454
bz = _open_bz("bugzilla.redhat.com")
4555
assert bz.is_xmlrpc()
4656
assert "/xmlrpc.cgi" in bz.url
57+
assert bz.__class__ is bugzilla.RHBugzilla
4758

4859
# See /rest in the URL, so use REST
4960
bz = _open_bz("bugzilla.redhat.com/rest")

0 commit comments

Comments
 (0)