From 1a72ff4c478c126293ee055bd2a743f0d67ee050 Mon Sep 17 00:00:00 2001 From: Jeff Bradberry Date: Wed, 19 Jun 2019 14:42:07 -0400 Subject: [PATCH] Use the `in` operator to test against the Organization membership subquery If more than one Organization were selected by this subquery, then Postgres would complain with "more than one row returned by a subquery used as an expression". We needed to allow for that case. Annoyingly SQLite3 doesn't seem to care, so writing a py.test test to exercise this isn't feasible under our current development setup. --- awx/main/access.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/awx/main/access.py b/awx/main/access.py index 09b16585e5..64933995bb 100644 --- a/awx/main/access.py +++ b/awx/main/access.py @@ -1265,7 +1265,7 @@ class TeamAccess(BaseAccess): (self.user.admin_of_organizations.exists() or self.user.auditor_of_organizations.exists()): return self.model.objects.all() return self.model.objects.filter( - Q(organization=Organization.accessible_pk_qs(self.user, 'member_role')) | + Q(organization__in=Organization.accessible_pk_qs(self.user, 'member_role')) | Q(pk__in=self.model.accessible_pk_qs(self.user, 'read_role')) )