Skip to content

Commit 7a6570f

Browse files
committed
bug: Simplify ID check and test it
1 parent 19415f4 commit 7a6570f

2 files changed

Lines changed: 10 additions & 8 deletions

File tree

bugzilla/bug.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,6 @@ def __init__(self, bugzilla, bug_id=None, dict=None, autorefresh=True):
4040
log.debug("Bug(%s)", sorted(dict.keys()))
4141
self._update_dict(dict)
4242

43-
if not hasattr(self, 'id'):
44-
raise TypeError("Bug object needs a bug_id")
45-
4643
self.weburl = bugzilla.url.replace('xmlrpc.cgi',
4744
'show_bug.cgi?id=%i' % self.bug_id)
4845

@@ -86,11 +83,6 @@ def __getattr__(self, name):
8683
if refreshed:
8784
break
8885

89-
if 'id' not in self.__dict__:
90-
# This is fatal, since we have no ID to pass to refresh()
91-
# Can happen if a messed up include_fields is passed to query
92-
raise AttributeError("No bug ID cached for bug object")
93-
9486
log.info("Bug %i missing attribute '%s' - doing implicit "
9587
"refresh(). This will be slow, if you want to avoid "
9688
"this, properly use query/getbug include_fields.",
@@ -139,6 +131,9 @@ def _update_dict(self, newdict):
139131
self._bug_fields.append(key)
140132
self.__dict__.update(newdict)
141133

134+
if 'id' not in self.__dict__ and 'bug_id' not in self.__dict__:
135+
raise TypeError("Bug object needs a bug_id")
136+
142137

143138
##################
144139
# pickle helpers #

tests/bug.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,10 @@ def _assert_bug():
6363
self.assertEqual(getattr(bug, "bugzilla"), None)
6464
bug.bugzilla = self.bz
6565
_assert_bug()
66+
67+
def testBugNoID(self):
68+
try:
69+
_Bug(bugzilla=self.bz, dict={"component": "foo"})
70+
raise AssertionError("Expected lack of ID failure.")
71+
except TypeError:
72+
pass

0 commit comments

Comments
 (0)