Merge lp://staging/~gmb/launchpad/bugzilla-3.4-bug-422848-bug-423046 into lp://staging/launchpad

Proposed by Graham Binns
Status: Merged
Merged at revision: not available
Proposed branch: lp://staging/~gmb/launchpad/bugzilla-3.4-bug-422848-bug-423046
Merge into: lp://staging/launchpad
Diff against target: None lines
To merge this branch: bzr merge lp://staging/~gmb/launchpad/bugzilla-3.4-bug-422848-bug-423046
Reviewer Review Type Date Requested Status
Gavin Panella (community) code Approve
Review via email: mp+11043@code.staging.launchpad.net

Commit message

Launchpad should now actually be able to import comments from Bugzilla 3.4. Really.

To post a comment you must log in.
Revision history for this message
Graham Binns (gmb) wrote :

This branch fixes a Schroedingbug that I discovered in the Bugzilla 3.4 compatibility work. Basically, we should never have been able to sync comments with Bugzilla 3.4 instances because the code didn't DTRT. I've now fixed this (*and* QA'd the fix against the Gnome Bugzilla for the sake of certainty).

Revision history for this message
Gavin Panella (allenap) wrote :

Wow, this stuff is quite painful.

We could consider using Zope schemas (or something else sensible) to help define and validate the data structures we pass between bug trackers. Lists of dicts and dicts within dicts and so on can get quite confusing as to what goes where.

review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/lp/bugs/externalbugtracker/bugzilla.py'
2--- lib/lp/bugs/externalbugtracker/bugzilla.py 2009-08-28 12:54:58 +0000
3+++ lib/lp/bugs/externalbugtracker/bugzilla.py 2009-09-02 08:32:27 +0000
4@@ -605,14 +605,16 @@
5
6 # Get only the remote comment IDs and store them in the
7 # 'comments' field of the bug.
8- bug_comments_dict = self.xmlrpc_proxy.Bug.comments({
9+ return_dict = self.xmlrpc_proxy.Bug.comments({
10 'ids': [actual_bug_id],
11 'include_fields': ['id'],
12 })
13
14 # We need to convert bug and comment ids to strings (see bugs
15 # 248662 amd 248938).
16- bug_comments = bug_comments_dict['bugs'][str(actual_bug_id)]
17+ bug_comments_dict = return_dict['bugs']
18+ bug_comments = bug_comments_dict[str(actual_bug_id)]['comments']
19+
20 return [str(comment['id']) for comment in bug_comments]
21
22 def fetchComments(self, bug_watch, comment_ids):
23@@ -636,7 +638,10 @@
24 if int(comment['bug_id']) != actual_bug_id:
25 del comments[comment_id]
26
27- self._bugs[actual_bug_id]['comments'] = return_dict['comments']
28+ # Ensure that comment IDs are converted to ints.
29+ comments_with_int_ids = dict(
30+ (int(id), comments[id]) for id in comments)
31+ self._bugs[actual_bug_id]['comments'] = comments_with_int_ids
32
33 def getPosterForComment(self, bug_watch, comment_id):
34 """See `ISupportsCommentImport`."""
35
36=== modified file 'lib/lp/bugs/tests/bugzilla-api-xmlrpc-transport.txt'
37--- lib/lp/bugs/tests/bugzilla-api-xmlrpc-transport.txt 2009-08-26 13:37:03 +0000
38+++ lib/lp/bugs/tests/bugzilla-api-xmlrpc-transport.txt 2009-09-02 09:18:14 +0000
39@@ -292,7 +292,7 @@
40 ... for key in sorted(bugs_dict):
41 ... print "Bug %s:" % key
42 ... bug_comments = sorted(
43- ... bugs_dict[key],
44+ ... bugs_dict[key]['comments'],
45 ... key=operator.itemgetter(sort_key))
46 ...
47 ... for comment in bug_comments:
48
49=== modified file 'lib/lp/bugs/tests/externalbugtracker.py'
50--- lib/lp/bugs/tests/externalbugtracker.py 2009-08-27 16:42:55 +0000
51+++ lib/lp/bugs/tests/externalbugtracker.py 2009-09-02 08:32:27 +0000
52@@ -916,8 +916,17 @@
53 # different when passed to TestBugzillaXMLRPCTransport.comments.
54 del comments_args['ids']
55 comments_args['bug_ids'] = arguments['ids']
56- [return_dict] = TestBugzillaXMLRPCTransport.comments(
57+ [returned_dict] = TestBugzillaXMLRPCTransport.comments(
58 self, comments_args)
59+
60+ # We need to move the comments for each bug in to a
61+ # 'comments' dict.
62+ bugs_dict = returned_dict['bugs']
63+ bug_comments_dict = {}
64+ for bug_id, comment_list in bugs_dict.items():
65+ bug_comments_dict[bug_id] = {'comments': comment_list}
66+
67+ return_dict = {'bugs': bug_comments_dict}
68 else:
69 return_dict = {'bugs': {}}
70