fix(invoiceintake): qualify order_by so Contact lookups by e-mail work
Every intake run failed with "list Contact: HTTP 500: (1052, Column 'creation' in ORDER BY is ambiguous)": the supplier lookup filters on the child table Contact Email, Frappe joins it, and the bare order_by column exists in both tables. Nothing sent to invoice@ became a draft (t53). order_by is now `tab<Doctype>`.`creation`; the fake ERP in the tests refuses an unqualified one with a child-table filter, like MariaDB. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KYcAAeTw22GE9QPzDM8yc4
This commit is contained in:
1 parent
4ab258c4b2
commit
7857fb4f09
2 files changed
+14
-1
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