fix(bolt): return empty slice for templates list with no rows (#3245)#3818
Open
omnidynmc wants to merge 1 commit intosemaphoreui:developfrom
Open
fix(bolt): return empty slice for templates list with no rows (#3245)#3818omnidynmc wants to merge 1 commit intosemaphoreui:developfrom
omnidynmc wants to merge 1 commit intosemaphoreui:developfrom
Conversation
GetTemplatesWithPermissions returned a nil []db.TemplateWithPerms when no templates matched. The named-return slice stayed nil because the loop over an empty result never appended, and nil marshals to JSON `null` instead of `[]`. The web UI's templates page expects an array and hangs on `null`, leaving the page on a perpetual loading spinner. The bug only manifests with the BoltDB driver — sqlx-backed dialects (SQLite / MySQL / Postgres) return non-nil slices because of how Scan populates them. Fixes semaphoreui#3245.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
BoltDb.GetTemplatesWithPermissionsreturns a nil[]db.TemplateWithPermswhen no templates match — the named-return slice stays nil because the loop over an emptyGetTemplatesresult never appends. Nil marshals to JSONnullinstead of[], and the web UI's templates page hangs on a perpetual loading spinner because the frontend tries to iterate over the response.The bug is BoltDB-specific. sqlx-backed dialects (SQLite/MySQL/Postgres) return non-nil slices because of how
Scanpopulates them, which matches multiple user reports in #3245 noting the issue disappears after switching off Bolt.The fix
One line in
GetTemplatesWithPermissions:before the append loop. Guarantees a non-nil slice for the empty case.
Test plan
Test_GetTemplatesWithPermissions_EmptyReturnsNonNilSliceregression test indb/bolt/template_test.gogo test ./db/bolt/...passes locally (Go 1.24)v2.17.39BoltDB deployment:/api/project/N/templatesreturns the literal stringnullfor empty projectsRelated
Fixes #3245. Multiple users (@codewest, @bearyjd, @SandraCHC, @vaemarr, @the-hotmann, @J-Bland) report this on BoltDB across v2.17.0 → v2.17.39.
There may be similar nil-slice bugs in other BoltDB list endpoints (inventory, repositories, environment, keys), but this PR is intentionally scoped to the symptom that wedges the UI. Happy to follow up with a broader sweep if reviewers want it in a separate PR.