Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 7, 2025

Updating a template via PUT /api/project/{project_id}/templates/{template_id} without including the vaults field in the request body deletes all existing vaults.

Changes

  • db/sql/template.go, db/bolt/template.go: Only call UpdateTemplateVaults when template.Vaults != nil
    • nil (field omitted) → preserve existing vaults
    • [] (empty array) → clear all vaults
    • [...] (populated array) → update vaults
// Before
func (d *SqlDb) UpdateTemplate(template db.Template) error {
    // ... update template fields ...
    err = d.UpdateTemplateVaults(template.ProjectID, template.ID, template.Vaults)
    return err
}

// After
func (d *SqlDb) UpdateTemplate(template db.Template) error {
    // ... update template fields ...
    if template.Vaults != nil {
        err = d.UpdateTemplateVaults(template.ProjectID, template.ID, template.Vaults)
    }
    return err
}
  • db/bolt/template_vault_test.go: Add tests covering nil, empty array, and explicit update scenarios
Original prompt

This section details on the original issue you should resolve

<issue_title>Problem: Unable to Update an Ansible Project Template when there are existing Vaults</issue_title>
<issue_description>### Issue

When trying to Update an existing Ansible Project Template:

HTTP PUT http://{{host}}:{{port}}/api/project//templates//

{
   ....
    "vaults": [
        {
            "name": "TEST",
            "type": "password",
            "vault_key_id": 7
        }
    ]
}

If the template already has a vault with the same template_id, vault_key_id, name which are basically the unique constraint in the table project__template_vault

400 Bad Request http error is generated.

Impact

Web-Backend (APIs)

Installation method

Package

Database

Postgres

Browser

Chrome

Semaphore Version

2.16.37

Ansible Version

2.16.4

Logs & errors

time="2025-11-06T19:52:49Z" level=error msg="pq: duplicate key value violates unique constraint \"project__template_vault_template_id_vault_key_id_name_key\""

Manual installation - system information

Photon 5

Configuration

NA

Additional information

Trying to Update an existing Ansible Project Template with the same vault should not raise an error.</issue_description>

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI changed the title [WIP] Fix unable to update Ansible project template with existing vaults Fix: Preserve template vaults when updating templates without vault field Nov 7, 2025
Copilot AI requested a review from fiftin November 7, 2025 14:52
Copilot finished work on behalf of fiftin November 7, 2025 14:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants