fix(invoiceintake): qualify order_by so Contact lookups by e-mail work #104
No files matched your search
@@ -50,7 +50,10 @@ func (c *frappe) list(ctx context.Context, doctype string, filters [][]any, fiel
|
||||
fl, _ := json.Marshal(fields)
|
||||
var all []json.RawMessage
|
||||
for start := 0; ; start += pageSize {
|
||||
q := url.Values{"filters": {string(f)}, "fields": {string(fl)}, "order_by": {"creation asc"},
|
||||
// Qualified: a filter on a child table (Contact Email) joins it, and
|
||||
// MariaDB refuses a bare "creation" as ambiguous.
|
||||
orderBy := fmt.Sprintf("`tab%s`.`creation` asc", doctype)
|
||||
q := url.Values{"filters": {string(f)}, "fields": {string(fl)}, "order_by": {orderBy},
|
||||
"limit_start": {fmt.Sprint(start)}, "limit_page_length": {fmt.Sprint(pageSize)}}
|
||||
var out struct {
|
||||
Data []json.RawMessage `json:"data"`
|
||||
|
||||
@@ -115,6 +115,16 @@ func (f *fakeERP) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
case r.Method == http.MethodGet && len(parts) == 1:
|
||||
var filters [][]any
|
||||
_ = json.Unmarshal([]byte(r.URL.Query().Get("filters")), &filters)
|
||||
// Like MariaDB: a filter on a child table joins it, and an unqualified
|
||||
// order_by column is then ambiguous (t53, "list Contact: HTTP 500").
|
||||
if ob := r.URL.Query().Get("order_by"); !strings.HasPrefix(ob, "`tab"+doctype+"`.") {
|
||||
for _, flt := range filters {
|
||||
if len(flt) == 4 && flt[0] != doctype {
|
||||
reply(500, map[string]any{"exception": "pymysql.err.OperationalError: (1052, \"Column 'creation' in ORDER BY is ambiguous\")"})
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
rows := f.find(doctype, filters)
|
||||
start, _ := strconv.Atoi(r.URL.Query().Get("limit_start"))
|
||||
n, _ := strconv.Atoi(r.URL.Query().Get("limit_page_length"))
|
||||
|
||||
Reference in new issue
Block a user