mirror of
https://github.com/frappe/erpnext.git
synced 2026-02-13 09:43:49 +00:00
fix(postgres): fix v15 migration failures on Postgres (#51481)
* fix(postgres): avoid DISTINCT(...) in repost allowed types query * fix(postgres): rewrite update pick list patch to avoid UPDATE JOIN * chore: linting changes --------- Co-authored-by: Matt Howard <github.severity519@passmail.net> Co-authored-by: ruthra kumar <ruthra@erpnext.com>
This commit is contained in:
@@ -215,16 +215,22 @@ def start_repost(account_repost_doc=str) -> None:
|
||||
|
||||
|
||||
def get_allowed_types_from_settings(child_doc: bool = False):
|
||||
repost_docs = [
|
||||
x.document_type
|
||||
for x in frappe.db.get_all(
|
||||
"Repost Allowed Types", filters={"allowed": True}, fields=["distinct(document_type)"]
|
||||
)
|
||||
]
|
||||
# Avoid DISTINCT(...) here: Frappe applies a default ORDER BY which breaks on Postgres
|
||||
# when used with SELECT DISTINCT.
|
||||
repost_docs = frappe.db.get_all(
|
||||
"Repost Allowed Types",
|
||||
filters={"allowed": True},
|
||||
pluck="document_type",
|
||||
)
|
||||
|
||||
# De-dupe while preserving order (first occurrence wins)
|
||||
repost_docs = list(dict.fromkeys(repost_docs))
|
||||
result = repost_docs
|
||||
|
||||
if repost_docs and child_doc:
|
||||
result.extend(get_child_docs(repost_docs))
|
||||
# Keep uniqueness after extending
|
||||
result = list(dict.fromkeys(result))
|
||||
|
||||
return result
|
||||
|
||||
@@ -291,8 +297,11 @@ def get_repost_allowed_types(doctype, txt, searchfield, start, page_len, filters
|
||||
if txt:
|
||||
filters.update({"document_type": ("like", f"%{txt}%")})
|
||||
|
||||
if allowed_types := frappe.db.get_all(
|
||||
"Repost Allowed Types", filters=filters, fields=["distinct(document_type)"], as_list=1
|
||||
):
|
||||
return allowed_types
|
||||
return []
|
||||
allowed_types = frappe.db.get_all(
|
||||
"Repost Allowed Types",
|
||||
filters=filters,
|
||||
pluck="document_type",
|
||||
)
|
||||
|
||||
allowed_types = list(dict.fromkeys(allowed_types))
|
||||
return [[dt] for dt in allowed_types]
|
||||
|
||||
@@ -8,12 +8,24 @@ def execute():
|
||||
|
||||
|
||||
def update_delivery_note():
|
||||
DN = frappe.qb.DocType("Delivery Note")
|
||||
DNI = frappe.qb.DocType("Delivery Note Item")
|
||||
|
||||
frappe.qb.update(DNI).join(DN).on(DN.name == DNI.parent).set(DNI.against_pick_list, DN.pick_list).where(
|
||||
IfNull(DN.pick_list, "") != ""
|
||||
).run()
|
||||
# Postgres doesn't support UPDATE ... JOIN. Use UPDATE ... FROM instead.
|
||||
frappe.db.multisql(
|
||||
{
|
||||
"mariadb": """
|
||||
UPDATE `tabDelivery Note Item` dni
|
||||
JOIN `tabDelivery Note` dn ON dn.`name` = dni.`parent`
|
||||
SET dni.`against_pick_list` = dn.`pick_list`
|
||||
WHERE COALESCE(dn.`pick_list`, '') <> ''
|
||||
""",
|
||||
"postgres": """
|
||||
UPDATE "tabDelivery Note Item" dni
|
||||
SET against_pick_list = dn.pick_list
|
||||
FROM "tabDelivery Note" dn
|
||||
WHERE dn.name = dni.parent
|
||||
AND COALESCE(dn.pick_list, '') <> ''
|
||||
""",
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
def update_pick_list_items():
|
||||
|
||||
Reference in New Issue
Block a user