Issues icon indicating copy to clipboard operation
Issues copied to clipboard

Error message when adding variable to variable set over REST api with missing Type property

Open benPearce1 opened this issue 9 months ago • 0 comments

Severity

Blocking some customers, but simple workaround available

Version

Tested on 2024.3, possibly been there since 2022.1

Latest Version

I could reproduce the problem in the latest build

What happened?

Attempting to create a new variable in an existing variable set via the REST will throw an Object reference not set to an instance of an object. error message if the variable is missing a Type value.

Reproduction

Perform a PUT operation against an existing variable set, where one of the variables, new or existing is missing a value for the Type property.

e.g

{
    "Id": "variableset-Projects-1281",
    "OwnerId": "Projects-1281",
    "Version": 1,
    "Variables": [
        {
            "Id": "1ff4e6c8-957e-1dcb-5e74-23ab40b78996",
            "Name": "var1",
            "Value": "value1",
            "Description": null,
            "Scope": {},
            "IsEditable": true,
            "Prompt": null,
            "IsSensitive": false
        },
    ],
    "ScopeValues": {
        ...snip...
    },
    "SpaceId": "Spaces-362",
    "Links": {
        "Self": "/api/Spaces-362/projects/Projects-1281/variables"
    }
}

Error and Stacktrace

System.NullReferenceException: Object reference not set to an instance of an object.
   at Octopus.Core.Features.Variables.VariableUpdater.ConvertToVariableDeclaration(IHaveVariables owner, VariableResource newResourceVariable, IReadOnlyDictionary`2 oldVariablesById) in ./source/Octopus.Core/Features/Variables/VariableUpdater.cs:line 143
   at Octopus.Core.Features.Variables.VariableUpdater.Update(VariableSet currentVariableSet, VariableSetResource updatedVariableSet, CancellationToken cancellationToken) in ./source/Octopus.Core/Features/Variables/VariableUpdater.cs:line 98
   at Octopus.Core.Features.Variables.ModifyProjectVariableSetCommandHandler.HandleInternal(Project project, VariableSetIdentifier variableSetId, IModifyProjectVariableSetCommand command, CancellationToken cancellationToken) in ./source/Octopus.Core/Features/Variables/ModifyProjectVariableSetCommandHandler.cs:line 78

More Information

No response

Workaround

Ensure all variables have a Type property. Valid values are String, Sensitive, Certificate, AmazonWebServicesAccount, AzureAcccount, GoogleCloudAccount, WorkerPool, or UsernamePasswordAccount

benPearce1 avatar May 23 '24 06:05 benPearce1