Skip to content

fix: stop mutating package-level columns variable in member list view#1002

Open
AdeshDeshmukh wants to merge 1 commit into
goharbor:mainfrom
AdeshDeshmukh:fix/member-list-global-columns-mutation
Open

fix: stop mutating package-level columns variable in member list view#1002
AdeshDeshmukh wants to merge 1 commit into
goharbor:mainfrom
AdeshDeshmukh:fix/member-list-global-columns-mutation

Conversation

@AdeshDeshmukh

Copy link
Copy Markdown

Description

ListMembers in pkg/views/member/list/view.go modifies a package-level var columns slice when rendering in non-wide mode. Since the variable is global, a non-wide call permanently strips columns from it — meaning subsequent calls with --wide will render an incomplete table.

This is a classic shared-mutable-state bug. The fix is straightforward: make a local copy at function entry and operate on that instead. The global now acts as an immutable template.

Changes

  • pkg/views/member/list/view.go — copy columns into a local variable, use it for both mutation and the table model

Testing

  • go build ./pkg/views/member/... — passes
  • go vet ./pkg/views/member/... — passes
  • Manually verified: harbor project member list and --wide both render correctly after the change

Fixes #3

Copilot AI review requested due to automatic review settings June 15, 2026 20:01

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

This PR updates member list rendering to avoid mutating the shared columns slice when switching between wide and non-wide output.

Changes:

  • Introduces localColumns to keep column changes local to ListMembers.
  • Uses localColumns when constructing the table model instead of the global columns.
Comments suppressed due to low confidence (1)

pkg/views/member/list/view.go:1

  • When wide is false, localColumns = utils.RemoveColumns(...) runs once per member even though the result is identical for every iteration. Compute localColumns once before the loop (based on wide) and only build rows inside the loop; this avoids repeated work and makes the control flow clearer.
// Copyright Project Harbor Authors

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.


func ListMembers(members []*models.ProjectMemberEntity, wide bool) {
var rows []table.Row
localColumns := columns
Comment thread pkg/views/member/list/view.go Outdated
} else {
colsToRemove := []string{"Role ID", "Project ID"}
columns = utils.RemoveColumns(columns, colsToRemove)
localColumns = utils.RemoveColumns(localColumns, colsToRemove)
Comment thread pkg/views/member/list/view.go Outdated
Comment on lines 65 to 67
colsToRemove := []string{"Role ID", "Project ID"}
columns = utils.RemoveColumns(columns, colsToRemove)
localColumns = utils.RemoveColumns(localColumns, colsToRemove)
rows = append(rows, table.Row{
The ListMembers function was modifying the global 'columns' variable
when rendering in non-wide mode via utils.RemoveColumns. This meant
that after the first non-wide call, every subsequent call — even with
--wide — would see a truncated set of columns.

Fix by making a local copy of the columns slice at the start of the
function and operating on that instead. The global now serves only as
a read-only template.

Fixes goharbor#3

Signed-off-by: Adesh Deshmukh <adeshkd123@gmail.com>
@AdeshDeshmukh AdeshDeshmukh force-pushed the fix/member-list-global-columns-mutation branch from 01f0703 to 9b6e3cd Compare June 15, 2026 20:09
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.

2 participants