Skip to content

fix(bolt): return empty slice for templates list with no rows (#3245)#3818

Open
omnidynmc wants to merge 1 commit intosemaphoreui:developfrom
omnidynmc:fix/bolt-empty-templates-nil-marshals-as-null
Open

fix(bolt): return empty slice for templates list with no rows (#3245)#3818
omnidynmc wants to merge 1 commit intosemaphoreui:developfrom
omnidynmc:fix/bolt-empty-templates-nil-marshals-as-null

Conversation

@omnidynmc
Copy link
Copy Markdown

Summary

BoltDb.GetTemplatesWithPermissions returns a nil []db.TemplateWithPerms when no templates match — the named-return slice stays nil because the loop over an empty GetTemplates result never appends. Nil marshals to JSON null instead 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 Scan populates them, which matches multiple user reports in #3245 noting the issue disappears after switching off Bolt.

The fix

One line in GetTemplatesWithPermissions:

templates = make([]db.TemplateWithPerms, 0, len(res))

before the append loop. Guarantees a non-nil slice for the empty case.

Test plan

  • Added Test_GetTemplatesWithPermissions_EmptyReturnsNonNilSlice regression test in db/bolt/template_test.go
  • go test ./db/bolt/... passes locally (Go 1.24)
  • Verified bug reproduces against v2.17.39 BoltDB deployment: /api/project/N/templates returns the literal string null for empty projects

Related

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.

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Problem: Page "Task Templates" doesnt load

1 participant