fix: stop mutating package-level columns variable in member list view#1002
Open
AdeshDeshmukh wants to merge 1 commit into
Open
fix: stop mutating package-level columns variable in member list view#1002AdeshDeshmukh wants to merge 1 commit into
AdeshDeshmukh wants to merge 1 commit into
Conversation
Contributor
There was a problem hiding this comment.
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
localColumnsto keep column changes local toListMembers. - Uses
localColumnswhen constructing the table model instead of the globalcolumns.
Comments suppressed due to low confidence (1)
pkg/views/member/list/view.go:1
- When
wideis false,localColumns = utils.RemoveColumns(...)runs once per member even though the result is identical for every iteration. ComputelocalColumnsonce before the loop (based onwide) and only buildrowsinside 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 |
| } else { | ||
| colsToRemove := []string{"Role ID", "Project ID"} | ||
| columns = utils.RemoveColumns(columns, colsToRemove) | ||
| localColumns = utils.RemoveColumns(localColumns, colsToRemove) |
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>
01f0703 to
9b6e3cd
Compare
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.
Description
ListMembersinpkg/views/member/list/view.gomodifies a package-levelvar columnsslice when rendering in non-wide mode. Since the variable is global, a non-wide call permanently strips columns from it — meaning subsequent calls with--widewill 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— copycolumnsinto a local variable, use it for both mutation and the table modelTesting
go build ./pkg/views/member/...— passesgo vet ./pkg/views/member/...— passesharbor project member listand--wideboth render correctly after the changeFixes #3