From 9f1915800fe8db603477b455ad32206e937764d5 Mon Sep 17 00:00:00 2001 From: Mihir Kandoi Date: Tue, 23 Jun 2026 09:13:49 +0530 Subject: [PATCH] fix(edi): make Common Code docname lookup valid on Postgres get_docnames_for issued SELECT DISTINCT on Dynamic Link.link_name while ordering by Dynamic Link.idx, a column absent from the select list. This is a raw frappe.qb query (run via .run(), not get_all/get_list), so the ORDER BY is emitted verbatim and PostgreSQL rejects it: 'for SELECT DISTINCT, ORDER BY expressions must appear in select list'. Order by link_name (the selected, distinct column) instead; same docnames on both engines, now deterministically ordered. --- erpnext/edi/doctype/code_list/code_list.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erpnext/edi/doctype/code_list/code_list.py b/erpnext/edi/doctype/code_list/code_list.py index e723157e7a0..b816f7dc3e7 100644 --- a/erpnext/edi/doctype/code_list/code_list.py +++ b/erpnext/edi/doctype/code_list/code_list.py @@ -116,7 +116,7 @@ def get_docnames_for(code_list: str, doctype: str, code: str) -> tuple[str]: & (CommonCode.code_list == code_list) ) .distinct() - .orderby(DynamicLink.idx) + .orderby(DynamicLink.link_name) ).run() return tuple(d[0] for d in docnames) if docnames else ()