From 26a4f6eeea7b6387f3d6a162d99475a078792704 Mon Sep 17 00:00:00 2001 From: Bin Liu Date: Sun, 17 Sep 2023 02:01:30 +0800 Subject: [PATCH] Remove duplicated sort fields from order by clause (#19347) In MustClone() it will set Sorts field twice, that will generate two duplicated order by fields in the generated SQL. Signed-off-by: bin liu --- src/lib/q/query.go | 1 - src/lib/q/query_test.go | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/q/query.go b/src/lib/q/query.go index e1bf9c21f..8910a0e40 100644 --- a/src/lib/q/query.go +++ b/src/lib/q/query.go @@ -56,7 +56,6 @@ func MustClone(query *Query) *Query { if query != nil { q.PageNumber = query.PageNumber q.PageSize = query.PageSize - q.Sorts = query.Sorts for k, v := range query.Keywords { q.Keywords[k] = v } diff --git a/src/lib/q/query_test.go b/src/lib/q/query_test.go index 3a76ccff2..e850ccf84 100644 --- a/src/lib/q/query_test.go +++ b/src/lib/q/query_test.go @@ -30,6 +30,7 @@ func TestMustClone(t *testing.T) { }{ {"ptr", args{New(KeyWords{"public": "true"})}, New(KeyWords{"public": "true"})}, {"nil", args{nil}, New(KeyWords{})}, + {"sort", args{&Query{Keywords: KeyWords{"public": "true"}, Sorts: []*Sort{NewSort("col-1", true)}}}, &Query{Keywords: KeyWords{"public": "true"}, Sorts: []*Sort{NewSort("col-1", true)}}}, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) {