Issues
Issues copied to clipboard
Saving a worker pool common variable to a tenant gives unhelpful error if connected projects have no environment
Team
- [X] I've assigned a team label to this issue
Severity
Minor, 1+ customer
Version
2022.3.9164-hotfix.10176
Latest Version
I could reproduce the problem in the latest build
What happened?
Saving a Worker Pool type Common Variable under Tenants > Variables throws a Sequence contains no elements
error if projects connected have no environments.
A bit more verbosity to the error would be good here or allow saving despite the project environments.
It's also odd that if you connect another Project to the tenant and DO define an environment the error does not happen and allows you to save like normal.
Reproduction
- Create a Library Variable Set
- Add a variable template -> Set as control type
Worker Pool
- Attach library variable set to a project
- Connect a tenant to that project but do not select an environment
- Try to change the value of the worker pool common variable under Tenant > Variables and save
- See error
Error and Stacktrace
System.InvalidOperationException: Sequence contains no elements
at System.Linq.ThrowHelper.ThrowNoElementsException()
at System.Linq.Enumerable.Aggregate[TSource](IEnumerable`1 source, Func`3 func)
at Octopus.Core.Security.Permissions.AccessCheckerExtensionMethods.AssertCanView[TModel](IAccessChecker`1 accessChecker, TModel model) in ./source/Octopus.Core/Security/Permissions/IAccessChecker.cs:line 28
at Octopus.Server.Web.Infrastructure.OctopusQueryExecutor.Load[TDocument,TKey](TKey id) in ./source/Octopus.Server/Web/Infrastructure/OctopusQueryExecutor.cs:line 200
at Octopus.Core.Persistence.Database.ProjectPathDecorators.ProjectPathQueryExecutorDecorator.Load[TDocument,TKey](TKey id) in ./source/Octopus.Core/Persistence/Database/ProjectPathDecorators/ProjectPathQueryExecutorDecorator.cs:line 35
at Octopus.Core.Auditing.EventStore.CaptureDiff[TDocument,TKey](IRawReadQueryExecutor session, Event event, TDocument model) in ./source/Octopus.Core/Auditing/EventStore.cs:line 136
at Octopus.Core.Auditing.EventStore.Store[TDocument,TKey](IRawWriteQueryExecutor session, Event event, TDocument model) in ./source/Octopus.Core/Auditing/EventStore.cs:line 86
at Octopus.Server.Web.Api.Actions.TenantVariableSynchronizer.SyncTenantVariables[THaveTemplates](Dictionary`2 postedVariableValues, List`1 existingVariableValues, THaveTemplates templateOwner, Tenant tenant, DeploymentEnvironmentId environmentId, TenantVariableSetOwnerType ownerType)
at Octopus.Server.Web.Api.Actions.TenantVariableSynchronizer.SyncLibraryVariables(TenantVariableResource resource, Tenant tenant, IReadOnlyCollection`1 projects, List`1 existingVariableValues) in ./source/Octopus.Server/Web/Api/Actions/TenantVariableSynchronizer.cs:line 91
at Octopus.Server.Web.Api.Actions.TenantVariableSynchronizer.SetModel(TenantVariableResource resource) in ./source/Octopus.Server/Web/Api/Actions/TenantVariableSynchronizer.cs:line 70
at Octopus.Server.Web.Controllers.Tenants.ModifyVariablesByTenantIdController.Modify(ModifyTenantVariablesRequest request, CancellationToken cancellationToken) in ./source/Octopus.Server/Web/Controllers/Tenants/ModifyVariablesByTenantIdController.cs:line 108
at Octopus.Server.Web.Controllers.Tenants.ModifyVariablesByTenantIdController.Put(ModifyTenantVariablesRequest request, CancellationToken cancellationToken) in ./source/Octopus.Server/Web/Controllers/Tenants/ModifyVariablesByTenantIdController.cs:line 77
at lambda_method4281116(Closure , Object )
at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.AwaitableObjectResultExecutor.Execute(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()
--- End of stack trace from previous location ---
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextResourceFilter>g__Awaited|25_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResourceExecutedContextSealed context)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.InvokeFilterPipelineAsync()
--- End of stack trace from previous location ---
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|6_0(Endpoint endpoint, Task requestTask, ILogger logger)
at Octopus.Server.Web.Infrastructure.Authentication.AuthorizationMiddlewareResultHandler.HandleAsync(RequestDelegate next, HttpContext context, AuthorizationPolicy policy, PolicyAuthorizationResult authorizeResult) in ./source/Octopus.Server/Web/Infrastructure/Authentication/AuthorizationMiddlewareResultHandler.cs:line 52
at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
at Octopus.Server.Web.UnitOfWorkMiddleware.InvokeAsync(HttpContext httpContext, IUnitOfWork unitOfWork) in ./source/Octopus.Server/Web/UnitOfWorkMiddleware.cs:line 47
at Octopus.Server.Web.UnitOfWorkMiddleware.InvokeAsync(HttpContext httpContext, IUnitOfWork unitOfWork) in ./source/Octopus.Server/Web/UnitOfWorkMiddleware.cs:line 47
at Octopus.Server.Web.Middleware.OctopusClientOldVersionWarningMiddleware.InvokeAsync(HttpContext context, IAutomationContext automationContext) in ./source/Octopus.Server/Web/Middleware/OctopusClientOldVersionWarningMiddleware.cs:line 53
at Octopus.Server.Web.Middleware.DynamicContentHeadersMiddleware.InvokeAsync(HttpContext context) in ./source/Octopus.Server/Web/Middleware/DynamicContentHeadersMiddleware.cs:line 49
at Octopus.Server.Web.Middleware.PrivateSpaceToggleMiddleware.InvokeAsync(HttpContext context) in ./source/Octopus.Server/Web/Middleware/PrivateSpaceToggleMiddleware.cs:line 56
at Octopus.Server.Web.Middleware.MaintenanceModeMiddleware.InvokeAsync(HttpContext context) in ./source/Octopus.Server/Web/Middleware/MaintenanceModeMiddleware.cs:line 61
at Octopus.Server.Web.Middleware.OctopusAuthenticationMiddleware.InvokeAsync(HttpContext context, IUserAuthenticator userAuthenticator, IAuthCookieService authCookieService, IWebAuthCache authCache, ILogger logger) in ./source/Octopus.Server/Web/Middleware/OctopusAuthenticationMiddleware.cs:line 57
at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
at Octopus.Server.Web.Middleware.LegacyRequestLoggerMiddleware.InvokeAsync(HttpContext context) in ./source/Octopus.Server/Web/Middleware/LegacyRequestLoggerMiddleware.cs:line 42
at Octopus.Server.Web.Middleware.TelemetryMiddleware.InvokeAsync(HttpContext context) in ./source/Octopus.Server/Web/Middleware/TelemetryMiddleware.cs:line 76
at Octopus.Server.Web.Middleware.ErrorHandlingMiddleware.InvokeAsync(HttpContext context) in ./source/Octopus.Server/Web/Middleware/ErrorHandlingMiddleware.cs:line 98
More Information
Customer Report: Internal Zendesk 🎫
Workaround
Re-connect the project to the tenant with an environment or attach another project that contains an environment.
Another affected customer (Internal link)
The error should probably be suppressed in favor of something more helpful to guide the user to add an Environment to the Tenant/Project connection