@@ -2215,12 +2215,18 @@ func (api *API) workspaceACL(rw http.ResponseWriter, r *http.Request) {
2215
2215
}
2216
2216
groupIDs = append (groupIDs ,id )
2217
2217
}
2218
- // For context see https://github.com/coder/coder/pull/19375
2219
- // nolint:gocritic
2220
- dbGroups ,err := api .Database .GetGroups (dbauthz .AsSystemRestricted (ctx ), database.GetGroupsParams {GroupIds :groupIDs })
2221
- if err != nil && ! xerrors .Is (err ,sql .ErrNoRows ) {
2222
- httpapi .InternalServerError (rw ,err )
2223
- return
2218
+
2219
+ // `GetGroups` returns all groups in the org if `GroupIds` is empty so we check
2220
+ // the length before making the DB call.
2221
+ dbGroups := make ([]database.GetGroupsRow ,0 )
2222
+ if len (groupIDs )> 0 {
2223
+ // For context see https://github.com/coder/coder/pull/19375
2224
+ // nolint:gocritic
2225
+ dbGroups ,err = api .Database .GetGroups (dbauthz .AsSystemRestricted (ctx ), database.GetGroupsParams {GroupIds :groupIDs })
2226
+ if err != nil && ! xerrors .Is (err ,sql .ErrNoRows ) {
2227
+ httpapi .InternalServerError (rw ,err )
2228
+ return
2229
+ }
2224
2230
}
2225
2231
2226
2232
groups := make ([]codersdk.WorkspaceGroup ,0 ,len (dbGroups ))