Merge ~cjwatson/launchpad:fix-stormify-person into launchpad:master

Proposed by Colin Watson
Status: Merged
Approved by: Colin Watson
Approved revision: 82a4af0e227ac60120313f2a41f5ffebd9c2e929
Merge reported by: Otto Co-Pilot
Merged at revision: not available
Proposed branch: ~cjwatson/launchpad:fix-stormify-person
Merge into: launchpad:master
Diff against target: 113 lines (+14/-9)
6 files modified
lib/lp/registry/model/distroseries.py (+1/-1)
lib/lp/registry/model/person.py (+5/-0)
lib/lp/registry/vocabularies.py (+1/-1)
lib/lp/translations/model/pofile.py (+1/-1)
lib/lp/translations/scripts/remove_translations.py (+2/-2)
lib/lp/translations/scripts/tests/test_remove_translations.py (+4/-4)
Reviewer Review Type Date Requested Status
Guruprasad Approve
Review via email: mp+451670@code.launchpad.net

Commit message

Fix test failures due to "Convert Person to Storm"

Description of the change

I had to reintroduce the old `Person._storm_sortingColumns`, but I took the opportunity to give it a less horribly confusing name and explain the circumstances where it's still needed. The other changes are just little details I got slightly wrong.

To post a comment you must log in.
Revision history for this message
Guruprasad (lgp171188) wrote :

LGTM 👍

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/lib/lp/registry/model/distroseries.py b/lib/lp/registry/model/distroseries.py
2index 4119824..2e19dfb 100644
3--- a/lib/lp/registry/model/distroseries.py
4+++ b/lib/lp/registry/model/distroseries.py
5@@ -1580,7 +1580,7 @@ class DistroSeries(
6 POTemplate.distroseries == self,
7 POTemplate.iscurrent == True,
8 )
9- contributors = contributors.order_by(*Person._sortingColumns)
10+ contributors = contributors.order_by(Person._separated_sortingColumns)
11 contributors = contributors.config(distinct=True)
12 return contributors
13
14diff --git a/lib/lp/registry/model/person.py b/lib/lp/registry/model/person.py
15index dcf118e..778f1dd 100644
16--- a/lib/lp/registry/model/person.py
17+++ b/lib/lp/registry/model/person.py
18@@ -498,6 +498,11 @@ class Person(
19 return self.id
20
21 sortingColumns = SQL("person_sort_key(Person.displayname, Person.name)")
22+ # If we're using SELECT DISTINCT, then we can't use sortingColumns
23+ # unless `person_sort_key(Person.displayname, Person.name)` is also in
24+ # the select list, which usually isn't convenient. Provide a separated
25+ # version instead.
26+ _separated_sortingColumns = ("Person.displayname", "Person.name")
27 # When doing any sort of set operations (union, intersect, except_) with
28 # Storm we can't use sortingColumns because the table name Person is not
29 # available in that context, so we use this one.
30diff --git a/lib/lp/registry/vocabularies.py b/lib/lp/registry/vocabularies.py
31index 0104a33..b267fec 100644
32--- a/lib/lp/registry/vocabularies.py
33+++ b/lib/lp/registry/vocabularies.py
34@@ -401,7 +401,7 @@ class UserTeamsParticipationVocabulary(StormVocabularyBase):
35 teams = list(
36 IStore(Person)
37 .find(Person, *clauses)
38- .order_by(Person._sortingColumns)
39+ .order_by(Person.sortingColumns)
40 )
41 # Users can view all the teams they belong to.
42 precache_permission_for_objects(
43diff --git a/lib/lp/translations/model/pofile.py b/lib/lp/translations/model/pofile.py
44index 623fb69..96196ca 100644
45--- a/lib/lp/translations/model/pofile.py
46+++ b/lib/lp/translations/model/pofile.py
47@@ -456,7 +456,7 @@ class POFile(StormBase, POFileMixIn):
48 )
49 .config(distinct=True)
50 )
51- contributors = contributors.order_by(*Person._sortingColumns)
52+ contributors = contributors.order_by(Person._separated_sortingColumns)
53 contributors = contributors.config(distinct=True)
54 return contributors
55
56diff --git a/lib/lp/translations/scripts/remove_translations.py b/lib/lp/translations/scripts/remove_translations.py
57index e854640..c042b8a 100644
58--- a/lib/lp/translations/scripts/remove_translations.py
59+++ b/lib/lp/translations/scripts/remove_translations.py
60@@ -444,11 +444,11 @@ def remove_translations(
61 conditions = set()
62 if submitter is not None:
63 conditions.add(
64- "TranslationMessage.submitter = %s" % sqlvalues(submitter.id)
65+ "TranslationMessage.submitter = %s" % sqlvalues(submitter)
66 )
67 if reviewer is not None:
68 conditions.add(
69- "TranslationMessage.reviewer = %s" % sqlvalues(reviewer.id)
70+ "TranslationMessage.reviewer = %s" % sqlvalues(reviewer)
71 )
72 if date_created is not None:
73 conditions.add(
74diff --git a/lib/lp/translations/scripts/tests/test_remove_translations.py b/lib/lp/translations/scripts/tests/test_remove_translations.py
75index 15c2638..dbea556 100644
76--- a/lib/lp/translations/scripts/tests/test_remove_translations.py
77+++ b/lib/lp/translations/scripts/tests/test_remove_translations.py
78@@ -420,7 +420,7 @@ class TestRemoveTranslations(TestCase):
79 # on reviewer instead.
80 new_nl_message.reviewer = self.potemplate.owner
81
82- self._removeMessages(submitter=carlos)
83+ self._removeMessages(submitter=carlos.id)
84 self._checkInvariant()
85
86 def test_RemoveByReviewer(self):
87@@ -434,7 +434,7 @@ class TestRemoveTranslations(TestCase):
88 new_nl_message.reviewer = carlos
89 new_de_message.reviewer = carlos
90
91- self._removeMessages(reviewer=carlos)
92+ self._removeMessages(reviewer=carlos.id)
93 self._checkInvariant()
94
95 def test_RemoveByDateCreated(self):
96@@ -473,7 +473,7 @@ class TestRemoveTranslations(TestCase):
97 )
98 removeSecurityProxy(new_de_message).submitter = mark
99
100- self._removeMessages(submitter=carlos, date_created="2015-05-12")
101+ self._removeMessages(submitter=carlos.id, date_created="2015-05-12")
102
103 # First make sure we're not reading out of cache.
104 Store.of(self.nl_pofile).flush()
105@@ -502,7 +502,7 @@ class TestRemoveTranslations(TestCase):
106 )
107
108 rowcount = self._removeMessages(
109- submitter=carlos, date_created="2015-05-12"
110+ submitter=carlos.id, date_created="2015-05-12"
111 )
112
113 self.assertEqual(rowcount, 1)

Subscribers

People subscribed via source and target branches

to status/vote changes: