← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] ~twom/launchpad:finding-a-500-isnt-useful into launchpad:master

 

Tom Wardill has proposed merging ~twom/launchpad:finding-a-500-isnt-useful into launchpad:master.

Commit message:
Fix OOPS with an empty search term 

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~twom/launchpad/+git/launchpad/+merge/383773
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of ~twom/launchpad:finding-a-500-isnt-useful into launchpad:master.
diff --git a/lib/lp/registry/model/distribution.py b/lib/lp/registry/model/distribution.py
index df02431..9c4c96e 100644
--- a/lib/lp/registry/model/distribution.py
+++ b/lib/lp/registry/model/distribution.py
@@ -1128,11 +1128,14 @@ class Distribution(SQLBase, BugTargetBase, MakesAnnouncements,
         # circular import
         from lp.registry.model.ociproject import OCIProject
         store = Store.of(self)
+        clauses = [OCIProject.distribution == self]
+        if text is not None:
+            clauses += [
+                OCIProject.ociprojectname_id == OCIProjectName.id,
+                OCIProjectName.name.contains_string(text)]
         return store.find(
             OCIProject,
-            OCIProject.distribution == self,
-            OCIProject.ociprojectname_id == OCIProjectName.id,
-            OCIProjectName.name.contains_string(text))
+            *clauses)
 
     def guessPublishedSourcePackageName(self, pkgname):
         """See `IDistribution`"""
diff --git a/lib/lp/registry/tests/test_distribution.py b/lib/lp/registry/tests/test_distribution.py
index f64e947..823048e 100644
--- a/lib/lp/registry/tests/test_distribution.py
+++ b/lib/lp/registry/tests/test_distribution.py
@@ -313,6 +313,15 @@ class TestDistribution(TestCaseWithFactory):
         result = distro.getOCIProject(first_project.name)
         self.assertEqual(first_project, result)
 
+    def test_searchOCIProjects_empty(self):
+        distro = self.factory.makeDistribution()
+        for _ in range(5):
+            self.factory.makeOCIProject(pillar=distro)
+        self.factory.makeOCIProject(pillar=distro)
+
+        result = distro.searchOCIProjects()
+        self.assertEqual(6, result.count())
+
     def test_searchOCIProjects_by_name(self):
         name = self.factory.getUniqueUnicode()
         distro = self.factory.makeDistribution()