Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

fix: list templates returns non-deprecated templates by default#17747

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
ssncferreira merged 8 commits intomainfromssncferreira/fix-deprecated-templates
May 13, 2025

Conversation

ssncferreira
Copy link
Contributor

Description

Modifies the behaviour of the "list templates" API endpoints to return non-deprecated templates by default. Users can still query for deprecated templates by specifying thedeprecated=true query parameter.

Note: The deprecation feature is an enterprise-level feature

Affected Endpoints

  • /api/v2/organizations/{organization}/templates
  • /api/v2/templates

Fixes#17565

@github-actionsGitHub Actions
Copy link

github-actionsbot commentedMay 9, 2025
edited
Loading

All contributors have signed the CLA ✍️ ✅
Posted by theCLA Assistant Lite bot.

@ssncferreirassncferreira changed the titleFix: list templates returns non-deprecated templates by defaultfix: list templates returns non-deprecated templates by defaultMay 9, 2025
@ssncferreira
Copy link
ContributorAuthor

I have read the CLA Document and I hereby sign the CLA

cdrci2 added a commit to coder/cla that referenced this pull requestMay 9, 2025
Copy link
Contributor

@cstyancstyan left a comment

Choose a reason for hiding this comment

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

Some style/organization comments, but I'm not sure about all the details of the preferred style for Go and tests here so curious what others have to say.

@@ -13021,7 +13021,7 @@ func (q *FakeQuerier) GetAuthorizedTemplates(ctx context.Context, arg database.G
if arg.ExactName != "" && !strings.EqualFold(template.Name, arg.ExactName) {
continue
}
if arg.Deprecated.Valid && arg.Deprecated.Bool== (template.Deprecated != "") {
if arg.Deprecated.Valid && arg.Deprecated.Bool!= (template.Deprecated != "") {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think a comment here might be useful as well. Initially I wanted to suggest renamingarg.Deprecated but I imagine that's a bigger change to roll out here. It's just not very nice to read this as something like

if arg.Deprecated.Valid && arg.IgnoreDeprecated && template.IsDeprecated

potentially the template struct could be refactored to haveIsDeprecated andDeprecatedMessage as opposed to just havingDeprecated message whose value being"some string" means the template is deprecated. Alternatively, the template could have a functionIsDeprecated?

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

I agree that the current expression witharg.Deprecated.Valid && arg.IgnoreDeprecated && template.Deprecated.Valid isn't the most readable.

Just for context: this method filters templates based on thearg param in the in-memory database used for testing. This logic ensures that only templates matching the requested deprecated state are returned.

TheDeprecated field is of typesql.NullBool, which is represented as:

type NullBool struct {Bool  boolValid bool // Valid is true if Bool is not NULL}

So we need to checkValid to avoid misinterpreting a NULL as false.

Thetemplate is of typedatabase.Template, generated bysqlc.
I could add a methodIsDeprecated to theTemplate struct to clean this up, but since that type is generated bysqlc, don't think it would be a good idea to add this type of custom logic directly at the DB layer. An alternative might be to define a wrapper around the generated type or introduce a view model in the service layer that handles this logic more cleanly but that may add more complexity than it solves, especially for a test-specific filter.

Copy link
Member

Choose a reason for hiding this comment

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

For readability I'd suggest a comment at most, or some light variable extraction.dbmem is only used for testing and it is planned to retire it at some point.

ssncferreira reacted with thumbs up emoji
Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

@cstyan added a comment infa8f999

cstyan reacted with thumbs up emoji
Copy link
Member

Choose a reason for hiding this comment

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

Reading this change a little more closely, doesn't this invert the query logic?

Comparing with the SQL:

-- Filter by deprecatedAND CASEWHENsqlc.narg('deprecated') ::booleanIS NOT NULL THENCASEWHENsqlc.narg('deprecated') ::boolean THENdeprecated!=''ELSEdeprecated=''ENDELSE trueEND

Aside: I've found it useful to comment the Go code in dbmem with the relevant parts of the corresponding SQL query.

Copy link
ContributorAuthor

@ssncferreirassncferreiraMay 13, 2025
edited
Loading

Choose a reason for hiding this comment

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

Yes, indbmem we are doing aninverse filtering to exclude non-matching templates.

In the SQL, we filter as follows:

  • Ifdeprecated is set totrue, we only include templates wheredeprecated != '', i.e., there is a deprecation message.
  • Ifdeprecated is set tofalse, we only include templates wheredeprecated = '', i.e., there is no deprecation message.
  • Ifdeprecated is not set (NULL), we include all templates (ELSE true clause).

In the in-memory logic we are doing aninverse filtering, thecontinue is used to exclude non-matching templates:

if arg.Deprecated.Valid && arg.Deprecated.Bool != (template.Deprecated != "") {  continue}

We skip templates when theDeprecated filter is set and the template's deprecation statusdoes not match theDeprecated value. This mirrors the behavior of the SQL CASE logic.

I think what’s confusing here is the double negation. I’ll improve the comment and maybe add a simpleisDeprecated function for readability.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Introduced a helper functionisDeprecated and improved the comment by adding the corresponding SQL logic for better readability:06acc27
@cstyan@johnstcn let me know if this makes it clearer 🙂

Copy link
Contributor

Choose a reason for hiding this comment

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

👍 I like it

@ssncferreirassncferreiraforce-pushed thessncferreira/fix-deprecated-templates branch 3 times, most recently from612391d tod9146c9CompareMay 12, 2025 11:31
@@ -13021,7 +13021,7 @@ func (q *FakeQuerier) GetAuthorizedTemplates(ctx context.Context, arg database.G
if arg.ExactName != "" && !strings.EqualFold(template.Name, arg.ExactName) {
continue
}
if arg.Deprecated.Valid && arg.Deprecated.Bool== (template.Deprecated != "") {
if arg.Deprecated.Valid && arg.Deprecated.Bool!= (template.Deprecated != "") {
Copy link
Member

Choose a reason for hiding this comment

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

For readability I'd suggest a comment at most, or some light variable extraction.dbmem is only used for testing and it is planned to retire it at some point.

ssncferreira reacted with thumbs up emoji
@ssncferreirassncferreiraforce-pushed thessncferreira/fix-deprecated-templates branch fromea595ed tofa8f999CompareMay 12, 2025 15:29
@ssncferreirassncferreira merged commit599bb35 intomainMay 13, 2025
36 checks passed
@ssncferreirassncferreira deleted the ssncferreira/fix-deprecated-templates branchMay 13, 2025 11:44
@github-actionsgithub-actionsbot locked and limited conversation to collaboratorsMay 13, 2025
Sign up for freeto subscribe to this conversation on GitHub. Already have an account?Sign in.
Reviewers

@cstyancstyancstyan left review comments

@johnstcnjohnstcnjohnstcn approved these changes

@DanielleMaywoodDanielleMaywoodAwaiting requested review from DanielleMaywood

@dannykoppingdannykoppingAwaiting requested review from dannykopping

Assignees

@ssncferreirassncferreira

Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

bug: Coder recommends deprecated templates to users
3 participants
@ssncferreira@cstyan@johnstcn

[8]ページ先頭

©2009-2025 Movatter.jp