Skip to content

fix: do not skip properties on creating templates - #5060

Merged
mtojek merged 2 commits into
coder:mainfrom
mtojek:3321-template-space-c
Nov 14, 2022
Merged

mtojek merged 2 commits into
coder:mainfrom
mtojek:3321-template-space-c

Conversation

@mtojek

@mtojek mtojek commented Nov 14, 2022

Copy link
Copy Markdown
Member

While working on #3321 I found that POST /templates rejects properties, even though the API contract expects it. This PR fixes the behavior.

@mtojek mtojek self-assigned this Nov 14, 2022
Comment thread cli/templateedit_test.go
assert.Equal(t, template.Description, updated.Description)
assert.Equal(t, template.DisplayName, updated.DisplayName)
// Icon is removed, as the API considers it as "delete" request
assert.Equal(t, "", updated.Icon)

@mtojek mtojek Nov 14, 2022 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is really unfortunate. If somebody runs coder templates edit <template-name>, they will automatically remove the icon. This is an outcome of not having a clear difference between delete icon and do not modify. Do you think that it's worth opening another issue?

EDIT:

Side issue - it isn't possible to clear the template description with UI. User can submit an empty description field, but the content is not deleted.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Considering the behavior here:

coder/coderd/templates.go

Lines 481 to 496 in 4b3d211

// Update template metadata -- empty fields are not overwritten.
name := req.Name
displayName := req.DisplayName
desc := req.Description
icon := req.Icon
maxTTL := time.Duration(req.DefaultTTLMillis) * time.Millisecond
if name == "" {
name = template.Name
}
if displayName == "" {
displayName = template.DisplayName
}
if desc == "" {
desc = template.Description
}

I would definitely consider it a bug. It's inconsistent how fields are affected. A missing field (null) should produce no change, an empty string should remove it and a non empty string change it. Feel free to open an issue about this. 👍🏻

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mtojek
mtojek marked this pull request as ready for review November 14, 2022 11:13
@mtojek
mtojek requested a review from a team November 14, 2022 11:13
Comment thread cli/templateedit_test.go
assert.Equal(t, template.Description, updated.Description)
assert.Equal(t, template.DisplayName, updated.DisplayName)
// Icon is removed, as the API considers it as "delete" request
assert.Equal(t, "", updated.Icon)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Considering the behavior here:

coder/coderd/templates.go

Lines 481 to 496 in 4b3d211

// Update template metadata -- empty fields are not overwritten.
name := req.Name
displayName := req.DisplayName
desc := req.Description
icon := req.Icon
maxTTL := time.Duration(req.DefaultTTLMillis) * time.Millisecond
if name == "" {
name = template.Name
}
if displayName == "" {
displayName = template.DisplayName
}
if desc == "" {
desc = template.Description
}

I would definitely consider it a bug. It's inconsistent how fields are affected. A missing field (null) should produce no change, an empty string should remove it and a non empty string change it. Feel free to open an issue about this. 👍🏻

@mtojek
mtojek merged commit cf5d48b into coder:main Nov 14, 2022
@github-actions github-actions Bot locked and limited conversation to collaborators Nov 14, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants