Skip to content

Commit 4823ef9

Browse files
committed
Bug: Track all API data internally as _rawdata
This simplifies things compared to just tracking the field names, at the expense of some memory, but will help implement things like CLI JSON output Signed-off-by: Cole Robinson <[email protected]>
1 parent 5184517 commit 4823ef9

1 file changed

Lines changed: 31 additions & 30 deletions

File tree

bugzilla/bug.py

Lines changed: 31 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def __init__(self, bugzilla, bug_id=None, dict=None, autorefresh=False):
2929
# API had pre-existing issue that we can't change ('dict' usage)
3030

3131
self.bugzilla = bugzilla
32-
self._bug_fields = []
32+
self._rawdata = {}
3333
self.autorefresh = autorefresh
3434

3535
if not dict:
@@ -111,41 +111,45 @@ def refresh(self, include_fields=None, exclude_fields=None,
111111
Refresh the bug with the latest data from bugzilla
112112
"""
113113
# pylint: disable=protected-access
114+
extra_fields = list(self._rawdata.keys()) + (extra_fields or [])
114115
r = self.bugzilla._getbug(self.bug_id,
115116
include_fields=include_fields, exclude_fields=exclude_fields,
116-
extra_fields=self._bug_fields + (extra_fields or []))
117+
extra_fields=extra_fields)
117118
# pylint: enable=protected-access
118119
self._update_dict(r)
119120
reload = refresh
120121

122+
def _translate_dict(self, newdict):
123+
if not self.bugzilla:
124+
return
125+
126+
self.bugzilla.post_translation({}, newdict)
127+
128+
# pylint: disable=protected-access
129+
aliases = self.bugzilla._get_bug_aliases()
130+
# pylint: enable=protected-access
131+
132+
for newname, oldname in aliases:
133+
if oldname not in newdict:
134+
continue
135+
136+
if newname not in newdict:
137+
newdict[newname] = newdict[oldname]
138+
elif newdict[newname] != newdict[oldname]:
139+
log.debug("Update dict contained differing alias values "
140+
"d[%s]=%s and d[%s]=%s , dropping the value "
141+
"d[%s]", newname, newdict[newname], oldname,
142+
newdict[oldname], oldname)
143+
del(newdict[oldname])
144+
145+
121146
def _update_dict(self, newdict):
122147
"""
123148
Update internal dictionary, in a way that ensures no duplicate
124149
entries are stored WRT field aliases
125150
"""
126-
if self.bugzilla:
127-
self.bugzilla.post_translation({}, newdict)
128-
129-
# pylint: disable=protected-access
130-
aliases = self.bugzilla._get_bug_aliases()
131-
# pylint: enable=protected-access
132-
133-
for newname, oldname in aliases:
134-
if oldname not in newdict:
135-
continue
136-
137-
if newname not in newdict:
138-
newdict[newname] = newdict[oldname]
139-
elif newdict[newname] != newdict[oldname]:
140-
log.debug("Update dict contained differing alias values "
141-
"d[%s]=%s and d[%s]=%s , dropping the value "
142-
"d[%s]", newname, newdict[newname], oldname,
143-
newdict[oldname], oldname)
144-
del(newdict[oldname])
145-
146-
for key in newdict.keys():
147-
if key not in self._bug_fields:
148-
self._bug_fields.append(key)
151+
self._translate_dict(newdict)
152+
self._rawdata.update(newdict)
149153
self.__dict__.update(newdict)
150154

151155
if 'id' not in self.__dict__ and 'bug_id' not in self.__dict__:
@@ -157,13 +161,10 @@ def _update_dict(self, newdict):
157161
##################
158162

159163
def __getstate__(self):
160-
ret = {}
161-
for key in self._bug_fields:
162-
ret[key] = self.__dict__[key]
163-
return ret
164+
return self._rawdata
164165

165166
def __setstate__(self, vals):
166-
self._bug_fields = []
167+
self._rawdata = {}
167168
self.bugzilla = None
168169
self._update_dict(vals)
169170

0 commit comments

Comments
 (0)