fix(invoiceintake): qualify order_by so Contact lookups by e-mail work #104

Merged
sharang merged 1 commits from fix/intake-contact-order into main 2026-10-29 11:38:47 +00:00
2 changed files with 14 additions and 1 deletions

No files matched your search

+4 -1
View File
@@ -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"`
+10
View File
@@ -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"))