diff --git a/server/src/main/java/com/cloud/user/AccountManagerImpl.java b/server/src/main/java/com/cloud/user/AccountManagerImpl.java index db9c1d1dafde..4ec6f63fe95e 100644 --- a/server/src/main/java/com/cloud/user/AccountManagerImpl.java +++ b/server/src/main/java/com/cloud/user/AccountManagerImpl.java @@ -1016,15 +1016,20 @@ protected boolean cleanupAccount(AccountVO account, long callerUserId, Account c logger.debug("Successfully deleted snapshots directories for all volumes under account {} across all zones", account); } + // clean up templates List userTemplates = _templateDao.listByAccountId(accountId); boolean allTemplatesDeleted = true; for (VMTemplateVO template : userTemplates) { if (template.getRemoved() == null) { try { - allTemplatesDeleted = _tmpltMgr.delete(callerUserId, template.getId(), null); + // Fix 1: Prevent boolean overwriting by checking failure explicitly + if (!_tmpltMgr.delete(callerUserId, template.getId(), null)) { + logger.warn("TemplateManager returned false when deleting template {} for account {}", template, account); + allTemplatesDeleted = false; + } } catch (Exception e) { - logger.warn("Failed to delete template {} while removing account {} due to: ", template, account, e); + logger.warn("Failed to delete template {} while removing account {} due to exception: ", template, account, e); allTemplatesDeleted = false; } }