Skip to content

Commit 44c396b

Browse files
committed
web: fix ambiguous column references in queries
When patch list queries join the submitter, state, and delegate relations, columns like "name" and "date" become ambiguous since they exist in multiple tables. Qualify all column references in filters and sort with the "patch." table prefix. Also fix the bundle list ORDER BY which is ambiguous with the owner relation joined. Signed-off-by: Robin Jarry <robin@jarry.cc>
1 parent 75edef3 commit 44c396b

3 files changed

Lines changed: 7 additions & 7 deletions

File tree

‎pkg/web/bundles.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ func (h *webHandler) ProjectBundleList(w http.ResponseWriter, r *http.Request) {
5858
ColumnExpr("*, (SELECT count(*) FROM bundle_patch WHERE bundle_id = bundle.id) AS patch_count").
5959
Relation("Owner").Relation("Project").
6060
Where("project_id = ?", project.ID).
61-
OrderExpr("name ASC")
61+
OrderExpr("bundle.name ASC")
6262

6363
user := getWebUser(r)
6464
if user != nil {

‎pkg/web/filters.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ func applyWebFilters(ctx context.Context, database bun.IDB, q *bun.SelectQuery,
2121
var filters []appliedFilter
2222

2323
if v := params.Get("q"); v != "" {
24-
q = q.Where("name LIKE ?", "%"+v+"%")
24+
q = q.Where("patch.name LIKE ?", "%"+v+"%")
2525
filters = append(filters, appliedFilter{
2626
Label: "Search",
2727
Value: v,

‎pkg/web/patches.go‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -683,11 +683,11 @@ func applySort(sq *bun.SelectQuery, sort string) *bun.SelectQuery {
683683
}
684684

685685
colMap := map[string]string{
686-
"date": "date",
687-
"name": "name",
688-
"submitter": "submitter_id",
689-
"delegate": "delegate_id",
690-
"state": "state_id",
686+
"date": "patch.date",
687+
"name": "patch.name",
688+
"submitter": "patch.submitter_id",
689+
"delegate": "patch.delegate_id",
690+
"state": "patch.state_id",
691691
}
692692

693693
col, ok := colMap[field]

0 commit comments

Comments
 (0)