Merge lp:~brian-murray/launchpad/api-export-bug-linked-branches-take2 into lp:launchpad

Proposed by Brian Murray
Status: Merged
Approved by: Michael Nelson
Approved revision: no longer in the source branch.
Merged at revision: not available
Proposed branch: lp:~brian-murray/launchpad/api-export-bug-linked-branches-take2
Merge into: lp:launchpad
Diff against target: 75 lines (+40/-3)
2 files modified
lib/lp/bugs/interfaces/bug.py (+7/-3)
lib/lp/bugs/stories/webservice/xx-bug.txt (+33/-0)
To merge this branch: bzr merge lp:~brian-murray/launchpad/api-export-bug-linked-branches-take2
Reviewer Review Type Date Requested Status
Michael Nelson (community) code Approve
Review via email: mp+20592@code.launchpad.net

Commit message

Exports IBug.linked_branches as an IBugBranch collection.

To post a comment you must log in.
Revision history for this message
Brian Murray (brian-murray) wrote :

This is a redo of the branch in https://code.edge.launchpad.net/~brian-murray/launchpad/api-export-bug-linked-branches. That was failing ec2 testing and make build due to the schema for linked branches being wrong. I've resolved that in this branch.

This may also resolve bug 528569.

Revision history for this message
Michael Nelson (michael.nelson) wrote :

Hi Brian, thanks for getting in there and fixing this.

I was a bit confused at first, as the original MP says it was merged (https://code.edge.launchpad.net/~brian-murray/launchpad/api-export-bug-linked-branches/+merge/17821) but I assume it didn't land.

Now, with this branch, I have one main question and a small request. The question is: Why are we declaring and exporting the the linked_branches CollectionField attribute on IBug, when it is already exported on IHasLinkedBranches (which is inherited by IBug)? I'll ping a bugs person to see if they know.

And regarding the tests, if you look at around line 1793 of xx-bug.txt, you'll see the "And for every bug we can look at the CVEs linked to it..." part of the story which shows how the exported cves_collection_link is used. It would be great to add a similar example showing the linked_branches_collection_link being used (you may need to first link a branch, I couldn't see a bug with any branches linked when I tried).

Thanks!
-Michael

review: Needs Information (code)
Revision history for this message
Abel Deuring (adeuring) wrote :

bugs 4 and 5 of the test data have linked branches

Revision history for this message
Abel Deuring (adeuring) wrote :

Ah, one more detail:

19 + linked_branches = exported(
20 + CollectionField(
21 + title=_("Branches associated with this bug, usually "
22 + "branches on which this bug is being fixed."),
23 + value_type=Reference(schema=IBranch),
24 + readonly=True))

That should be "schema=IBugBranch", as the implementation lp.bugs.model.Bug.linked_branches returns BugBranch objects.

Revision history for this message
Michael Nelson (michael.nelson) wrote :

Hi Brian,

So from the conversation below, I now understand why the original MP says Merged, and why you're needing to re-define linked_branches on IBug (because the declaration on IHasLinkedBranches uses the schema IBranch, whereas Abel mentions below that IBugBranch should be the used as the schema, as it has a few extra fields.)

So, please switch the schema to IBugBranch (I just checked and your current test still passes), and then add the example showing how it can be used (as mentioned above for cves_collection_link in the same test) - this will show the extra fields provided by IBugBranch - and it should be good to land.

Thanks!

10:04 < noodles775> Hi adeuring, would you be able to have a look at the comment I just added to https://code.edge.launchpad.net/~brian-murray/launchpad/api-export-bug-linked-branches-take2/+merge/20592
10:04 < noodles775> adeuring: do you know if there's a reason why linked_branches is declared both in IBug and IHasLinkedBranches (which is inherited by IBug)?
10:05 < adeuring> noodles775: more or less. (1) class IBugBranch defines a few more properties, like revision_hint or bug_task
10:06 < adeuring> erm that was it, no (2)
10:07 < adeuring> noodles775: and the history of Brian's branch is quite complex. It was merged into a another branch, and that branch landed after Brian's changed had been reverted.
10:08 < noodles775> adeuring: sorry, I don't understand what that has to do with IBug.linked_branches and IHasLinkedBranches.linked_branches, when IBug inherits IHasLinkedBranches
10:08 < noodles775> adeuring: oh, ok.
10:08 < adeuring> noodles775: yes, that's quite convoluted ;)
10:09 < noodles775> adeuring: the declaration should only be required on IHasLinkedBranches right? (although the test fails if you remove the one on IBug)? Or what did I miss?
10:09 < adeuring> noodles775: and: Brian should use IBugBranch as the reference type
10:10 < adeuring> noodles775: sorry wrote the last line too early...
10:10 < adeuring> we need the new declaration at least now, for the export, because of schema=IBranch, which is wrong
10:11 < adeuring> it should be schema=IBugBranch, in the export declaration
10:11 < noodles775> Ah, so it's actually meant to override the IHasLinkedBranches declaration?
10:12 < noodles775> (as it uses the wrong schema). OK.
10:12 < adeuring> noodles775: well, I did not write the code ;) But I assume, yes
10:12 < noodles775> adeuring: ok, thanks for the help!
10:16 < adeuring> noodles775: an odd detail of overriding linked_branches is that there is not very much left from IHasLinkedBranches ;) But that's nothing we should nag Brain with ;)
10:17 < noodles775> adeuring: yes, afaics IHasLinkedBranches is used by other objects (blueprints).
10:17 < adeuring> right

review: Needs Fixing (code)
Revision history for this message
Brian Murray (brian-murray) wrote :

I've made the recommended changes and pushed them in revision 10429.

Revision history for this message
Michael Nelson (michael.nelson) wrote :

Great stuff, thanks Brian.

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/interfaces/bug.py'
2--- lib/lp/bugs/interfaces/bug.py 2010-02-27 10:19:18 +0000
3+++ lib/lp/bugs/interfaces/bug.py 2010-03-04 18:54:33 +0000
4@@ -36,6 +36,7 @@
5 from lp.bugs.interfaces.bugtask import (
6 BugTaskImportance, BugTaskStatus, IBugTask)
7 from lp.bugs.interfaces.bugwatch import IBugWatch
8+from lp.bugs.interfaces.bugbranch import IBugBranch
9 from lp.bugs.interfaces.cve import ICve
10 from canonical.launchpad.interfaces.launchpad import IPrivacy, NotFoundError
11 from canonical.launchpad.interfaces.message import IMessage
12@@ -250,9 +251,12 @@
13 readonly=True))
14 questions = Attribute("List of questions related to this bug.")
15 specifications = Attribute("List of related specifications.")
16- linked_branches = Attribute(
17- "Branches associated with this bug, usually "
18- "branches on which this bug is being fixed.")
19+ linked_branches = exported(
20+ CollectionField(
21+ title=_("Branches associated with this bug, usually "
22+ "branches on which this bug is being fixed."),
23+ value_type=Reference(schema=IBugBranch),
24+ readonly=True))
25 tags = exported(
26 List(title=_("Tags"), description=_("Separated by whitespace."),
27 value_type=Tag(), required=False))
28
29=== modified file 'lib/lp/bugs/stories/webservice/xx-bug.txt'
30--- lib/lp/bugs/stories/webservice/xx-bug.txt 2010-02-12 09:54:48 +0000
31+++ lib/lp/bugs/stories/webservice/xx-bug.txt 2010-03-04 18:54:33 +0000
32@@ -32,6 +32,7 @@
33 duplicates_collection_link: u'http://.../bugs/11/duplicates'
34 heat: 0
35 id: 11
36+ linked_branches_collection_link: u'http://.../bugs/11/linked_branches'
37 messages_collection_link: u'http://.../bugs/11/messages'
38 name: None
39 number_of_duplicates: 0
40@@ -1957,3 +1958,35 @@
41 >>> for submission in linked_submissions['entries']:
42 ... print submission['submission_key']
43 private-submission
44+
45+Bug branches
46+------------
47+
48+For every bug we can look at the branches linked to it.
49+
50+ >>> bug_four = webservice.get("/bugs/4").jsonBody()
51+ >>> bug_four_branches_url = bug_four['linked_branches_collection_link']
52+ >>> bug_four_branches = webservice.get(bug_four_branches_url).jsonBody()
53+ >>> pprint_collection(bug_four_branches)
54+ resource_type_link: u'http://.../#bug_branch-page-resource'
55+ start: 0
56+ total_size: 2
57+ ---
58+ branch_link: u'http://.../~mark/firefox/release-0.9.2'
59+ bug_link: u'http://.../bugs/4'
60+ resource_type_link: u'http://.../#bug_branch'
61+ self_link: u'http://.../~mark/firefox/release-0.9.2/+bug/4'
62+ ---
63+ branch_link: u'http://.../~name12/firefox/main'
64+ bug_link: u'http://.../bugs/4'
65+ resource_type_link: u'http://.../beta/#bug_branch'
66+ self_link: u'http://.../~name12/firefox/main/+bug/4'
67+ ---
68+
69+For every branch we can also look at the bugs linked to it.
70+
71+ >>> branch_entry = bug_four_branches['entries'][0]
72+ >>> bug_link = webservice.get(
73+ ... branch_entry['bug_link']).jsonBody()
74+ >>> print bug_link['self_link']
75+ http://.../bugs/4