Skip to content

Commit

Permalink
fix: rewrite query for postgres (#20557) (#20558)
Browse files Browse the repository at this point in the history
(cherry picked from commit fa32b61)

Co-authored-by: Ankush Menat <ankush@frappe.io>
  • Loading branch information
mergify[bot] and ankush committed Apr 3, 2023
1 parent 616dd8b commit e400c5f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
6 changes: 5 additions & 1 deletion frappe/contacts/doctype/address/address.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,11 @@ def address_query(doctype, txt, searchfield, start, page_len, filters):
({search_condition})
{mcond} {condition}
order by
if(locate(%(_txt)s, `tabAddress`.name), locate(%(_txt)s, `tabAddress`.name), 99999),
case
when locate(%(_txt)s, `tabAddress`.name) != 0
then locate(%(_txt)s, `tabAddress`.name)
else 99999
end,
`tabAddress`.idx desc, `tabAddress`.name
limit %(page_len)s offset %(start)s""".format(
mcond=get_match_cond(doctype),
Expand Down
2 changes: 1 addition & 1 deletion frappe/contacts/doctype/address/test_address.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,5 @@ def query(doctype="Address", txt="", searchfield="name", start=0, page_len=20, f
}
).insert()

self.assertGreaterEqual(len(query(txt="admin")), 1)
self.assertGreaterEqual(len(query(txt="Admin")), 1)
self.assertEqual(len(query(txt="what_zyx")), 0)

0 comments on commit e400c5f

Please sign in to comment.