From 925d181f0b39d5fb079331e330989822e0ce8001 Mon Sep 17 00:00:00 2001 From: Wei Zhou Date: Fri, 29 Sep 2023 10:58:03 +0200 Subject: [PATCH] server: fix mysql error when list Shared templates for project MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit without this PR ``` (localcloud) 🐱 > list templates listall=true templatefilter=shared showunique=true projectid=-1 🙈 Error: (HTTP 530, error code 4250) DB Exception on: com.mysql.cj.jdbc.ClientPreparedStatement: SELECT DISTINCT(template_view.id) FROM template_view WHERE template_view.account_type = 5 AND template_view.lp_account_id IN ) AND template_view.hypervisor_type='KVM' AND template_view.format != 'ISO' AND template_view.template_state IN ('Active','UploadAbandoned','UploadError','NotUploaded','UploadInProgress') AND template_view.removed IS NULL ORDER BY template_view.sort_key ASC , template_view.temp_zone_pair ASC LIMIT 0, 500 ``` with this PR, it returns empty result --- server/src/main/java/com/cloud/api/query/QueryManagerImpl.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/server/src/main/java/com/cloud/api/query/QueryManagerImpl.java b/server/src/main/java/com/cloud/api/query/QueryManagerImpl.java index c28865943a96..08f18faba28a 100644 --- a/server/src/main/java/com/cloud/api/query/QueryManagerImpl.java +++ b/server/src/main/java/com/cloud/api/query/QueryManagerImpl.java @@ -3758,6 +3758,9 @@ else if (!template.isPublicTemplate() && caller.getType() != Account.Type.ADMIN) } } else if (templateFilter == TemplateFilter.sharedexecutable || templateFilter == TemplateFilter.shared) { // only show templates shared by others + if (permittedAccounts.isEmpty()) { + return new Pair<>(new ArrayList<>(), 0); + } sc.addAnd("sharedAccountId", SearchCriteria.Op.IN, permittedAccountIds.toArray()); } else if (templateFilter == TemplateFilter.executable) { SearchCriteria scc = _templateJoinDao.createSearchCriteria();