Skip to content

Variable sets cannot be deleted when used snapshots for a version controlled runbook #9618

@bec-callow-oct

Description

@bec-callow-oct

Severity

Known impact to one customer, no workaround exists

Version

2025.2.12902

Latest Version

I could reproduce the problem in the latest build

What happened?

Runbook snapshots cannot be deleted for version controlled runbooks. When one of these snapshots uses a variable set, that variable set also cannot be deleted because it requires the snapshots to be removed first.

Reproduction

Create a variable set
Create a config as code project, connect to a tenant and include the variable set
Create a runbook and add a Run a Script step using the variable set
Run the runbook to generate a snapshot
Navigate to the variable set and find the snapshot under Usages
Click on the snapshot, and click the 3 dots to try to delete. The delete button is not shown.
Exclude the variable set from the project and try to delete the set. Receive error The variable set can't be deleted because it's currently being referenced in a release or runbook snapshot.

Error and Stacktrace

"Exception of type 'Octopus.Core.Model.CannotDeleteReferencedResourceException' was thrown."
Octopus.Core.Model.CannotDeleteReferencedResourceException: Exception of type 'Octopus.Core.Model.CannotDeleteReferencedResourceException' was thrown.
   at Octopus.Core.Persistence.Database.Deletion.DocumentDeletionVetoCheck`2.EnsureCanBeDeleted(TDocument model, CancellationToken cancellationToken) in C:\Users\BecCallow\RiderProjects\OctopusWorktrees\2025.2\source\Octopus.Core\Persistence\Database\Deletion\DocumentDeletionVetoCheck.cs:line 46
   at Octopus.Core.Persistence.Database.Deletion.VetoDocumentStoreDecorator`2.RemoveAsync(TDocument document, CancellationToken cancellationToken, Boolean enforceVetoRules) in C:\Users\BecCallow\RiderProjects\OctopusWorktrees\2025.2\source\Octopus.Core\Persistence\Database\Deletion\VetoDocumentStoreDecorator.cs:line 59
   at Octopus.Core.Persistence.Database.AccessCheckingDocumentStoreDecorator`2.RemoveAsync(TDocument document, CancellationToken cancellationToken, Boolean enforceVetoRules) in C:\Users\BecCallow\RiderProjects\OctopusWorktrees\2025.2\source\Octopus.Core\Persistence\Database\AccessCheckingDocumentStoreDecorator.cs:line 100
   at Octopus.Core.Persistence.DocumentStore`2.RemoveAsync(TDocument document, CancellationToken cancellationToken, Boolean enforceVetoRules) in C:\Users\BecCallow\RiderProjects\OctopusWorktrees\2025.2\source\Octopus.Core\Persistence\DocumentStore.cs:line 99
   at Octopus.Core.Features.LibraryVariableSets.DeleteLibraryVariableSetCommandHandler.Handle(DeleteLibraryVariableSetCommand command, CancellationToken cancellationToken) in C:\Users\BecCallow\RiderProjects\OctopusWorktrees\2025.2\source\Octopus.Core\Features\LibraryVariableSets\DeleteLibraryVariableSetCommandHandler.cs:line 25
   at Octopus.Core.Infrastructure.Mediator.AutofacMediator.Do[TCommand,TResponse](ICommand`2 command, CancellationToken cancellationToken) in C:\Users\BecCallow\RiderProjects\OctopusWorktrees\2025.2\source\Octopus.Core\Infrastructure\Mediator\AutofacMediator.cs:line 33
   at Octopus.Core.Infrastructure.Mediator.Decorators.SystemComponentModelValidationDecorator.Do[TCommand,TResponse](ICommand`2 command, CancellationToken cancellationToken) in C:\Users\BecCallow\RiderProjects\OctopusWorktrees\2025.2\source\Octopus.Core\Infrastructure\Mediator\Decorators\SystemComponentModelValidationDecorator.cs:line 28
   at Octopus.Core.Infrastructure.Mediator.Decorators.FluentValidationsDecorator.Do[TCommand,TResponse](ICommand`2 command, CancellationToken cancellationToken) in C:\Users\BecCallow\RiderProjects\OctopusWorktrees\2025.2\source\Octopus.Core\Infrastructure\Mediator\Decorators\FluentValidationsDecorator.cs:line 35
   at Octopus.Core.Infrastructure.Mediator.Decorators.MessageBusSiphoningDecorator.Do[TCommand,TResponse](ICommand`2 command, CancellationToken cancellationToken) in C:\Users\BecCallow\RiderProjects\OctopusWorktrees\2025.2\source\Octopus.Core\Infrastructure\Mediator\Decorators\MessageBusSiphoningDecorator.cs:line 32
   at Octopus.Server.Web.Controllers.LibraryVariableSets.DeleteLibraryVariableSetController.DeleteLibraryVariableSet(DeleteLibraryVariableSetCommand command, CancellationToken cancellationToken) in C:\Users\BecCallow\RiderProjects\OctopusWorktrees\2025.2\source\Octopus.Server\Web\Controllers\LibraryVariableSets\DeleteLibraryVariableSetController.cs:line 21
   at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.TaskResultExecutor.Execute(ActionContext actionContext, IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeActionMethodAsync>g__Logged|12_1(ControllerActionInvoker invoker)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeNextActionFilterAsync>g__Awaited|10_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Rethrow(ActionExecutedContextSealed context)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeInnerFilterAsync>g__Awaited|13_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeFilterPipelineAsync>g__Awaited|20_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Logged|17_1(ResourceInvoker invoker)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Logged|17_1(ResourceInvoker invoker)
   at Microsoft.AspNetCore.Routing.EndpointMiddleware.<Invoke>g__AwaitRequestTask|7_0(Endpoint endpoint, Task requestTask, ILogger logger)
   at Octopus.Server.Web.Middleware.BoundaryTrailerRewriteMiddleware.Invoke(HttpContext context, IAutomationContext automationContext) in C:\Users\BecCallow\RiderProjects\OctopusWorktrees\2025.2\source\Octopus.Server\Web\Middleware\BoundaryTrailerRewriteMiddleware.cs:line 45
   at Octopus.Server.Web.Middleware.OpenFeatureUserContextMiddleware.InvokeAsync(HttpContext httpContext, IOctopusPrincipalInternal principal, IFeatureClient client) in C:\Users\BecCallow\RiderProjects\OctopusWorktrees\2025.2\source\Octopus.Server\Web\Middleware\OpenFeatureUserContextMiddleware.cs:line 30
   at Octopus.Server.Web.Infrastructure.Authentication.AuthorizationMiddlewareResultHandler.HandleAsync(RequestDelegate next, HttpContext context, AuthorizationPolicy policy, PolicyAuthorizationResult authorizeResult) in C:\Users\BecCallow\RiderProjects\OctopusWorktrees\2025.2\source\Octopus.Server\Web\Infrastructure\Authentication\AuthorizationMiddlewareResultHandler.cs:line 50
   at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
   at Octopus.Server.Web.UnitOfWorkMiddleware.InvokeAsync(HttpContext httpContext, IUnitOfWork unitOfWork) in C:\Users\BecCallow\RiderProjects\OctopusWorktrees\2025.2\source\Octopus.Server\Web\UnitOfWorkMiddleware.cs:line 31
   at Octopus.Server.Web.UnitOfWorkMiddleware.InvokeAsync(HttpContext httpContext, IUnitOfWork unitOfWork) in C:\Users\BecCallow\RiderProjects\OctopusWorktrees\2025.2\source\Octopus.Server\Web\UnitOfWorkMiddleware.cs:line 42
   at Octopus.Server.Web.Middleware.OctopusClientOldVersionWarningMiddleware.InvokeAsync(HttpContext context, IAutomationContext automationContext) in C:\Users\BecCallow\RiderProjects\OctopusWorktrees\2025.2\source\Octopus.Server\Web\Middleware\OctopusClientOldVersionWarningMiddleware.cs:line 24
   at Octopus.Server.Web.Middleware.DynamicContentHeadersMiddleware.InvokeAsync(HttpContext context) in C:\Users\BecCallow\RiderProjects\OctopusWorktrees\2025.2\source\Octopus.Server\Web\Middleware\DynamicContentHeadersMiddleware.cs:line 50
   at Octopus.Server.Web.Middleware.MaintenanceModeMiddleware.InvokeAsync(HttpContext context) in C:\Users\BecCallow\RiderProjects\OctopusWorktrees\2025.2\source\Octopus.Server\Web\Middleware\MaintenanceModeMiddleware.cs:line 66
   at Octopus.Server.Web.Middleware.OctopusAuthenticationMiddleware.InvokeAsync(HttpContext context, IUserAuthenticator userAuthenticator, IUserSessionService userSessionService, IWebAuthCache authCache, ILogger logger) in C:\Users\BecCallow\RiderProjects\OctopusWorktrees\2025.2\source\Octopus.Server\Web\Middleware\OctopusAuthenticationMiddleware.cs:line 70
   at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
   at Octopus.Server.Web.Middleware.TelemetryMiddleware.InvokeAsync(HttpContext context) in C:\Users\BecCallow\RiderProjects\OctopusWorktrees\2025.2\source\Octopus.Server\Web\Middleware\TelemetryMiddleware.cs:line 64
   at Octopus.Server.Web.Middleware.ErrorHandlingMiddleware.InvokeAsync(HttpContext context) in C:\Users\BecCallow\RiderProjects\OctopusWorktrees\2025.2\source\Octopus.Server\Web\Middleware\ErrorHandlingMiddleware.cs:line 47
"HTTP" "DELETE" to "localhost:8066""/api/Spaces-1/libraryvariablesets/LibraryVariableSets-21" "completed" with 400 in 00:00:00.0340756 (34ms) by "admin"

More Information

No response

Workaround

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind/bugThis issue represents a verified problem we are committed to solving

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions