Merge lp:~jtv/launchpad/bug-435699 into lp:launchpad/db-devel

Proposed by Jeroen T. Vermeulen
Status: Merged
Merged at revision: not available
Proposed branch: lp:~jtv/launchpad/bug-435699
Merge into: lp:launchpad/db-devel
Diff against target: 82 lines
2 files modified
lib/lp/translations/model/potemplate.py (+4/-0)
lib/lp/translations/tests/test_autoapproval.py (+32/-8)
To merge this branch: bzr merge lp:~jtv/launchpad/bug-435699
Reviewer Review Type Date Requested Status
Brad Crittenden (community) release-critical Approve
Michael Nelson (community) code Approve
Review via email: mp+12338@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Jeroen T. Vermeulen (jtv) wrote :

= Bug 435699 =

To fix crashes in the translations auto-approver last cycle, I rewrote
POTemplateSet.getPOTemplateByPathAndOrigin. Where the old version would
crash if multiple templates matched (which happened rarely, fortunately)
the new version detected the condition and logged it.

Now, post-rollout, I find that it logs far too much. As it turns out,
the new version forgets to match on distroseries, so any template that
exists unchanged between Ubuntu releases will seem to have multiple
matches!

This branch fixes that. A test broke in the process, but that seems to
be from using a fixed name for a package, and then not _passing_ the
distroseries argument to getPOTemplateByPathAndOrigin. To stay faithful
to the known interface, which does not require the distroseries argument
(even if it's probably always given in practice), I fixed it by using a
unique name for the package.

What I test for is not the logging, but the more serious consequence of
the condition that's beeing seen (and logged) where it isn't supposed to
be: multiple matches mean that templates are not found, and so uploads
are not approved.

Test:
{{{
./bin/test test_autoapproval
}}}

No lint.

Jeroen

Revision history for this message
Michael Nelson (michael.nelson) wrote :
Download full text (6.0 KiB)

Hi Jeroen,

r=me

Thanks for the details in the MP!

> = Bug 435699 =
>
> To fix crashes in the translations auto-approver last cycle, I rewrote
> POTemplateSet.getPOTemplateByPathAndOrigin. Where the old version would
> crash if multiple templates matched (which happened rarely, fortunately)
> the new version detected the condition and logged it.
>
> Now, post-rollout, I find that it logs far too much. As it turns out,
> the new version forgets to match on distroseries, so any template that
> exists unchanged between Ubuntu releases will seem to have multiple
> matches!

OK - at first I thought - why's this an rc? But yes, with the info in your
last para - it makes more sense!

>
> This branch fixes that. A test broke in the process, but that seems to
> be from using a fixed name for a package, and then not _passing_ the
> distroseries argument to getPOTemplateByPathAndOrigin. To stay faithful
> to the known interface, which does not require the distroseries argument
> (even if it's probably always given in practice), I fixed it by using a
> unique name for the package.
>
> What I test for is not the logging, but the more serious consequence of
> the condition that's beeing seen (and logged) where it isn't supposed to
> be: multiple matches mean that templates are not found, and so uploads
> are not approved.
>
> Test:
> {{{
> ./bin/test test_autoapproval
> }}}
>
> No lint.
>
>
> Jeroen

> === modified file 'lib/lp/translations/model/potemplate.py'
> --- lib/lp/translations/model/potemplate.py 2009-09-17 04:51:07 +0000
> +++ lib/lp/translations/model/potemplate.py 2009-09-24 09:48:24 +0000
> @@ -1225,6 +1225,10 @@
> POTemplate.from_sourcepackagename == sourcepackagename,
> POTemplate.sourcepackagename == sourcepackagename))
>
> + if distroseries:
> + conditions = And(
> + conditions, POTemplate.distroseries == distroseries)
> +

You probably already know, but just in case, another way to do this
is to use a list of extra expressions and just append to it (rather than
wrapping further conditions in And exprs (for eg., Archive.getBuildCounters()).

> store = IStore(POTemplate)
> matches = helpers.shortlist(store.find(POTemplate, conditions))
>
>
> === modified file 'lib/lp/translations/tests/test_autoapproval.py'
> --- lib/lp/translations/tests/test_autoapproval.py 2009-09-15 05:25:13 +0000
> +++ lib/lp/translations/tests/test_autoapproval.py 2009-09-24 09:48:24 +0000
> @@ -272,6 +272,12 @@
> self.producttemplate2 = product_subset.new(
> 'test2', 'test2', 'test.pot', self.product.owner)
>
> + def _makeTemplateForDistroSeries(self, distroseries, name):
> + """Create a template in the given `DistroSeries`."""
> + distro_subset = POTemplateSubset(
> + distroseries=distroseries, sourcepackagename=self.packagename)
> + return distro_subset.new(name, name, 'test.pot', self.distro.owner)
> +

Great.

> def _setUpDistro(self):
> """Set up a `Distribution` with two templates."""
> self.distro = self.factory.makeDistribution()
> @@ -279,13 +285,10 @@
> distri...

Read more...

review: Approve (code)
Revision history for this message
Brad Crittenden (bac) :
review: Approve (release-critical)
Revision history for this message
Brad Crittenden (bac) wrote :

Please add the additional comments as we discussed.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'lib/lp/translations/model/potemplate.py'
--- lib/lp/translations/model/potemplate.py 2009-09-17 04:51:07 +0000
+++ lib/lp/translations/model/potemplate.py 2009-09-24 15:05:26 +0000
@@ -1225,6 +1225,10 @@
1225 POTemplate.from_sourcepackagename == sourcepackagename,1225 POTemplate.from_sourcepackagename == sourcepackagename,
1226 POTemplate.sourcepackagename == sourcepackagename))1226 POTemplate.sourcepackagename == sourcepackagename))
12271227
1228 if distroseries:
1229 conditions = And(
1230 conditions, POTemplate.distroseries == distroseries)
1231
1228 store = IStore(POTemplate)1232 store = IStore(POTemplate)
1229 matches = helpers.shortlist(store.find(POTemplate, conditions))1233 matches = helpers.shortlist(store.find(POTemplate, conditions))
12301234
12311235
=== modified file 'lib/lp/translations/tests/test_autoapproval.py'
--- lib/lp/translations/tests/test_autoapproval.py 2009-09-15 05:25:13 +0000
+++ lib/lp/translations/tests/test_autoapproval.py 2009-09-24 15:05:26 +0000
@@ -272,6 +272,12 @@
272 self.producttemplate2 = product_subset.new(272 self.producttemplate2 = product_subset.new(
273 'test2', 'test2', 'test.pot', self.product.owner)273 'test2', 'test2', 'test.pot', self.product.owner)
274274
275 def _makeTemplateForDistroSeries(self, distroseries, name):
276 """Create a template in the given `DistroSeries`."""
277 distro_subset = POTemplateSubset(
278 distroseries=distroseries, sourcepackagename=self.packagename)
279 return distro_subset.new(name, name, 'test.pot', self.distro.owner)
280
275 def _setUpDistro(self):281 def _setUpDistro(self):
276 """Set up a `Distribution` with two templates."""282 """Set up a `Distribution` with two templates."""
277 self.distro = self.factory.makeDistribution()283 self.distro = self.factory.makeDistribution()
@@ -279,13 +285,10 @@
279 distribution=self.distro)285 distribution=self.distro)
280 self.packagename = SourcePackageNameSet().new('package')286 self.packagename = SourcePackageNameSet().new('package')
281 self.from_packagename = SourcePackageNameSet().new('from')287 self.from_packagename = SourcePackageNameSet().new('from')
282 distro_subset = POTemplateSubset(288 self.distrotemplate1 = self._makeTemplateForDistroSeries(
283 distroseries=self.distroseries,289 self.distroseries, 'test1')
284 sourcepackagename=self.packagename)290 self.distrotemplate2 = self._makeTemplateForDistroSeries(
285 self.distrotemplate1 = distro_subset.new(291 self.distroseries, 'test2')
286 'test1', 'test1', 'test.pot', self.distro.owner)
287 self.distrotemplate2 = distro_subset.new(
288 'test2', 'test2', 'test.pot', self.distro.owner)
289292
290 def test_ByPathAndOrigin_product_duplicate(self):293 def test_ByPathAndOrigin_product_duplicate(self):
291 # When multiple templates match for a product series,294 # When multiple templates match for a product series,
@@ -311,11 +314,32 @@
311 'test.pot', sourcepackagename=self.from_packagename)314 'test.pot', sourcepackagename=self.from_packagename)
312 self.assertEqual(None, guessed_template)315 self.assertEqual(None, guessed_template)
313316
317 def test_ByPathAndOrigin_similar_between_distroseries(self):
318 # getPOTemplateByPathAndOrigin disregards templates from other
319 # distroseries.
320 self._setUpDistro()
321 other_series = self.factory.makeDistroRelease(
322 distribution=self.distro)
323 other_template = self._makeTemplateForDistroSeries(
324 other_series, 'test1')
325 self.distrotemplate1.iscurrent = False
326 self.distrotemplate2.iscurrent = True
327 self.distrotemplate1.from_sourcepackagename = None
328 self.distrotemplate2.from_sourcepackagename = None
329 guessed_template = self.templateset.getPOTemplateByPathAndOrigin(
330 'test.pot', distroseries=self.distroseries,
331 sourcepackagename=self.packagename)
332 self.assertEqual(self.distrotemplate2, guessed_template)
333
314 def test_ByPathAndOrigin_preferred_match(self):334 def test_ByPathAndOrigin_preferred_match(self):
315 # getPOTemplateByPathAndOrigin prefers from_sourcepackagename335 # getPOTemplateByPathAndOrigin prefers from_sourcepackagename
316 # matches over sourcepackagename matches.336 # matches over sourcepackagename matches.
317 self._setUpDistro()337 self._setUpDistro()
318 match_package = SourcePackageNameSet().new('match-package')338 # Use unique name for this package, since the search does not
339 # pass a distroseries and so might pick one of the same name up
340 # from elsewhere.
341 match_package = SourcePackageNameSet().new(
342 self.factory.getUniqueString())
319 self.distrotemplate1.sourcepackagename = match_package343 self.distrotemplate1.sourcepackagename = match_package
320 self.distrotemplate2.from_sourcepackagename = match_package344 self.distrotemplate2.from_sourcepackagename = match_package
321345

Subscribers

People subscribed via source and target branches

to status/vote changes: