Merge ~cjwatson/launchpad:archiveauthtoken-multiple-subscriptions into launchpad:master

Proposed by Colin Watson
Status: Merged
Approved by: Colin Watson
Approved revision: 77e5133ee6f5e4d7dfe3f46fd1dfd84ee2155146
Merge reported by: Otto Co-Pilot
Merged at revision: not available
Proposed branch: ~cjwatson/launchpad:archiveauthtoken-multiple-subscriptions
Merge into: launchpad:master
Diff against target: 55 lines (+17/-2)
2 files modified
lib/lp/soyuz/doc/archiveauthtoken.txt (+16/-1)
lib/lp/soyuz/model/archiveauthtoken.py (+1/-1)
Reviewer Review Type Date Requested Status
Cristian Gonzalez (community) Approve
Review via email: mp+400549@code.launchpad.net

Commit message

Fix ArchiveAuthToken lookup with multiple subscriptions

Description of the change

When querying for tokens with current subscriptions, `ArchiveAuthTokenSet.getByArchive` could return multiple rows even though there was only a single token due to the additional joins. Add `DISTINCT` to avoid this.

To post a comment you must log in.
Revision history for this message
Cristian Gonzalez (cristiangsp) wrote :

Looks good!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
diff --git a/lib/lp/soyuz/doc/archiveauthtoken.txt b/lib/lp/soyuz/doc/archiveauthtoken.txt
index c6c3fa3..c02db56 100644
--- a/lib/lp/soyuz/doc/archiveauthtoken.txt
+++ b/lib/lp/soyuz/doc/archiveauthtoken.txt
@@ -21,7 +21,7 @@ New tokens are created using IArchive.newAuthToken() but this is only
21possible if there is already a valid subscription for the user for21possible if there is already a valid subscription for the user for
22that archive.22that archive.
2323
24Create Brad, and his team:24Create Brad, and his teams:
2525
26 >>> login("admin@canonical.com")26 >>> login("admin@canonical.com")
27 >>> bradsmith = factory.makePerson(27 >>> bradsmith = factory.makePerson(
@@ -29,6 +29,8 @@ Create Brad, and his team:
29 ... email="brad@example.com")29 ... email="brad@example.com")
30 >>> teambrad = factory.makeTeam(30 >>> teambrad = factory.makeTeam(
31 ... owner=bradsmith, displayname="Team Brad", name='teambrad')31 ... owner=bradsmith, displayname="Team Brad", name='teambrad')
32 >>> teambrad2 = factory.makeTeam(
33 ... owner=bradsmith, displayname="Team Brad 2", name='teambrad2')
3234
33Create a subscription for Team Brad to joe's archive:35Create a subscription for Team Brad to joe's archive:
3436
@@ -169,6 +171,19 @@ Tokens are only returned if they match a current subscription:
169 >>> removeSecurityProxy(subscription_to_joe_private_ppa).status = (171 >>> removeSecurityProxy(subscription_to_joe_private_ppa).status = (
170 ... ArchiveSubscriberStatus.CURRENT)172 ... ArchiveSubscriberStatus.CURRENT)
171173
174Retrieving tokens works even if the user is subscribed to the archive via
175multiple paths:
176
177 >>> _ = login_person(joe)
178 >>> _ = joe_private_ppa.newSubscription(teambrad2, joe)
179 >>> login("brad@example.com")
180 >>> print(token_set.getActiveTokenForArchiveAndPerson(
181 ... new_token.archive, new_token.person).token)
182 testtoken
183 >>> print(token_set.getActiveTokenForArchiveAndPersonName(
184 ... new_token.archive, "bradsmith").token)
185 testtoken
186
172187
173== Amending Tokens ==188== Amending Tokens ==
174189
diff --git a/lib/lp/soyuz/model/archiveauthtoken.py b/lib/lp/soyuz/model/archiveauthtoken.py
index 2dfe646..3d39143 100644
--- a/lib/lp/soyuz/model/archiveauthtoken.py
+++ b/lib/lp/soyuz/model/archiveauthtoken.py
@@ -103,7 +103,7 @@ class ArchiveAuthTokenSet:
103 ArchiveSubscriber.subscriber_id == TeamParticipation.teamID,103 ArchiveSubscriber.subscriber_id == TeamParticipation.teamID,
104 TeamParticipation.personID == ArchiveAuthToken.person_id,104 TeamParticipation.personID == ArchiveAuthToken.person_id,
105 ])105 ])
106 return store.find(ArchiveAuthToken, *clauses)106 return store.find(ArchiveAuthToken, *clauses).config(distinct=True)
107107
108 def getActiveTokenForArchiveAndPerson(self, archive, person):108 def getActiveTokenForArchiveAndPerson(self, archive, person):
109 """See `IArchiveAuthTokenSet`."""109 """See `IArchiveAuthTokenSet`."""

Subscribers

People subscribed via source and target branches

to status/vote changes: