[PATCH] Handle getting project list for new users

martin f. krafft madduck at madduck.net
Tue Feb 2 20:58:03 EST 2010

UserProfile.contributor_projects gets the list of patches belonging to
any of the user's email addresses, and then obtains the list of projects
based on where these patches have been sent.

If a new user has not sent any patches (or has not been associated with
any), then the eventual Project ResultSet is empty, and it seems that
Django doesn't like when .query is accessed (models.py:95).

This patch hence first checks the length of the Projects ResultSet and
only invokes the query if it's len>0, else returns an empty list.

Signed-off-by: martin f. krafft <madduck at madduck.net>
 apps/patchwork/models.py |    9 ++++-----
 1 files changed, 4 insertions(+), 5 deletions(-)

diff --git a/apps/patchwork/models.py b/apps/patchwork/models.py
index ffefb11..830d409 100644
--- a/apps/patchwork/models.py
+++ b/apps/patchwork/models.py
@@ -88,12 +88,11 @@ class UserProfile(models.Model):
     def contributor_projects(self):
         submitters = Person.objects.filter(user = self.user)
-        return Project.objects \
-            .filter(id__in = \
-                    Patch.objects.filter(
-                        submitter__in = submitters) \
-                    .values('project_id').query)
+        projects = Project.objects.filter(id__in = \
+            Patch.objects.filter(submitter__in = submitters))
+        if not projects: return []
+        return projects.values('project_id').query
     def sync_person(self):

More information about the Patchwork mailing list