Chained GORM conditions on a pinned connection can leak into the next query

Open
#2,146 0 comments 0 reactions 1 assignee View on GitHub

Maintainers usually reply within 1 day

@Wikid82 is already working on this.

Since Dec 3, 2026.

Assessment

This issue has not been assessed yet.

Description

backend bug low

What: a function that runs more than one query on a pinned *gorm.DB connection (for example the single-connection migration path, backend/internal/api/routes/migrate.go) can have conditions from one query carry into the next, because GORM builds on the receiver's existing statement unless a fresh session is started. This was hit while writing services.KeepManagementCountryListsExcludingLocal (added in PR closing #1895/#1980): a follow-up query on the same pinned connection picked up a leftover key = ? condition from an earlier, unrelated query and failed with "no such column: uuid". The fix there was to start each query from conn.Session(&gorm.Session{NewDB: true}).

Where: any function that chains more than one top-level query call against a single pinned connection, including other migration-path or management-access helpers in backend/internal/services/management_access.go (for example ManagementListUUIDs, if called more than once from the same pinned connection without an intervening fresh session).

Suggested approach: audit callers that reuse a pinned connection across more than one query and have them call .Session(&gorm.Session{NewDB: true}) (or an equivalent fresh-statement pattern) before each independent query, rather than relying on the caller never chaining unrelated conditions.

Severity: low (correctness/reliability only, no data exposure — surfaces as a query failure, not a wrong result returned to a caller).

Found during B8-05 implementation.

Dominant language
Go
Stars
17
Forks
2
Avg merge
1h 42m
Merged PRs (30d)
173

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from Wikid82/Charon

All issues in Wikid82/Charon

Similar issues

More Go issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.