diff --git a/data/model/organization.py b/data/model/organization.py index 003e55f5b..a855385e9 100644 --- a/data/model/organization.py +++ b/data/model/organization.py @@ -79,22 +79,24 @@ def remove_organization_member(org, user_obj): raise DataModelException('Cannot remove user as they are the only organization admin') with db_transaction(): - # Find and remove the user from any repositorys under the org. - permissions = (RepositoryPermission - .select(RepositoryPermission.id) - .join(Repository) - .where(Repository.namespace_user == org, - RepositoryPermission.user == user_obj)) + # Find and remove the user from any repositories under the org. + permissions = list(RepositoryPermission + .select(RepositoryPermission.id) + .join(Repository) + .where(Repository.namespace_user == org, + RepositoryPermission.user == user_obj)) - RepositoryPermission.delete().where(RepositoryPermission.id << permissions).execute() + if permissions: + RepositoryPermission.delete().where(RepositoryPermission.id << permissions).execute() # Find and remove the user from any teams under the org. - members = (TeamMember - .select(TeamMember.id) - .join(Team) - .where(Team.organization == org, TeamMember.user == user_obj)) + members = list(TeamMember + .select(TeamMember.id) + .join(Team) + .where(Team.organization == org, TeamMember.user == user_obj)) - TeamMember.delete().where(TeamMember.id << members).execute() + if members: + TeamMember.delete().where(TeamMember.id << members).execute() def get_organization_member_set(orgname):