fix: Revert changes made to fix collation differences
Due to collation differences in MariaDB and Postgres, tests gave inconsistent results. This was to be handled in tests alone instead of the application. It was unnecessary. Collation changes should be made at DBMS config level only. Accomodating for those in the application will unnecessarily degrade performance for everyone. Other changes: * use pluck in user_type * revert ordering in nestedset * revert parsing in order_field * use preferred APIs & styling Co-authored-by: gavin <gavin18d@gmail.com>
This commit is contained in:
parent
1c40881c41
commit
55392b64e7
4 changed files with 37 additions and 33 deletions
|
|
@ -36,20 +36,15 @@ class UserType(Document):
|
|||
if not self.user_doctypes:
|
||||
return
|
||||
|
||||
DocType = frappe.qb.DocType("DocType")
|
||||
modules = frappe.get_all("DocType",
|
||||
filters={"name": ("in", [d.document_type for d in self.user_doctypes])},
|
||||
distinct=True,
|
||||
pluck="module",
|
||||
)
|
||||
|
||||
document_types = [d.document_type for d in self.user_doctypes] or ['']
|
||||
modules = (frappe.qb.from_(DocType)
|
||||
.select(DocType.module)
|
||||
.where(DocType.name.isin(document_types))
|
||||
.groupby(DocType.module)
|
||||
.distinct()).run()
|
||||
|
||||
self.set('user_type_modules', [])
|
||||
for row in modules:
|
||||
self.append('user_type_modules', {
|
||||
'module': row[0]
|
||||
})
|
||||
self.set("user_type_modules", [])
|
||||
for module in modules:
|
||||
self.append("user_type_modules", {"module": module})
|
||||
|
||||
def validate_document_type_limit(self):
|
||||
limit = frappe.conf.get('user_type_doctype_limit', {}).get(frappe.scrub(self.name))
|
||||
|
|
|
|||
|
|
@ -1,24 +1,33 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Copyright (c) 2019, Frappe Technologies and contributors
|
||||
# Copyright (c) 2022, Frappe Technologies and contributors
|
||||
# License: MIT. See LICENSE
|
||||
|
||||
from frappe.model.document import Document
|
||||
from frappe.modules.export_file import export_to_files
|
||||
from frappe.config import get_modules_from_all_apps_for_user
|
||||
import json
|
||||
|
||||
import frappe
|
||||
from frappe import _
|
||||
import json
|
||||
from frappe.config import get_modules_from_all_apps_for_user
|
||||
from frappe.model.document import Document
|
||||
from frappe.modules.export_file import export_to_files
|
||||
from frappe.query_builder import DocType
|
||||
|
||||
|
||||
class Dashboard(Document):
|
||||
def on_update(self):
|
||||
if self.is_default:
|
||||
# make all other dashboards non-default
|
||||
DashBoard = frappe.qb.DocType("Dashboard")
|
||||
|
||||
frappe.qb.update(DashBoard).set(DashBoard.is_default, 0).where(DashBoard.name != self.name).run()
|
||||
DashBoard = DocType("Dashboard")
|
||||
|
||||
frappe.qb.update(DashBoard).set(
|
||||
DashBoard.is_default, 0
|
||||
).where(
|
||||
DashBoard.name != self.name
|
||||
).run()
|
||||
|
||||
if frappe.conf.developer_mode and self.is_standard:
|
||||
export_to_files(record_list=[['Dashboard', self.name, self.module + ' Dashboard']], record_module=self.module)
|
||||
export_to_files(
|
||||
record_list=[["Dashboard", self.name, f"{self.module} Dashboard"]],
|
||||
record_module=self.module
|
||||
)
|
||||
|
||||
def validate(self):
|
||||
if not frappe.conf.developer_mode and self.is_standard:
|
||||
|
|
|
|||
|
|
@ -213,8 +213,11 @@ class DatabaseQuery(object):
|
|||
order_field = order_field.replace(r, "")
|
||||
|
||||
if order_field not in args.fields:
|
||||
order_fieldm = order_field.replace("`", '"')
|
||||
args.fields += f", MAX({order_fieldm}) as `{order_fieldm}`"
|
||||
order_fieldm = order_field.replace("`", "")
|
||||
if "." in order_fieldm:
|
||||
args.fields += ", MAX(" + order_fieldm.split(".")[1] + ") as `" + order_fieldm + "`"
|
||||
else:
|
||||
args.fields += ", MAX(" + order_fieldm + ") as `" + order_fieldm + "`"
|
||||
args.order_by = args.order_by.replace(order_field, "`" + order_fieldm + "`")
|
||||
|
||||
return args
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
|
||||
# Copyright (c) 2022, Frappe Technologies Pvt. Ltd. and Contributors
|
||||
# License: MIT. See LICENSE
|
||||
|
||||
# Tree (Hierarchical) Nested Set Model (nsm)
|
||||
|
|
@ -16,9 +16,6 @@ import frappe
|
|||
from frappe import _
|
||||
from frappe.model.document import Document
|
||||
from frappe.query_builder import DocType, Order
|
||||
from pypika import CustomFunction
|
||||
|
||||
Replace = CustomFunction('REPLACE', ['input', 'substr_to_replace', 'substr_to_replace_with'])
|
||||
|
||||
class NestedSetRecursionError(frappe.ValidationError): pass
|
||||
class NestedSetMultipleRootsError(frappe.ValidationError): pass
|
||||
|
|
@ -91,7 +88,7 @@ def update_move_node(doc, parent_field):
|
|||
|
||||
if parent:
|
||||
new_parent = frappe.db.sql("""select lft, rgt from `tab{0}`
|
||||
where name = %s for update""".format(doc.doctype), parent, as_dict=1)[0]
|
||||
where name = %s for update""".format(doc.doctype), parent, as_dict=1)[0]
|
||||
|
||||
validate_loop(doc.doctype, doc.name, new_parent.lft, new_parent.rgt)
|
||||
|
||||
|
|
@ -110,7 +107,7 @@ def update_move_node(doc, parent_field):
|
|||
|
||||
if parent:
|
||||
new_parent = frappe.db.sql("""select lft, rgt from `tab%s`
|
||||
where name = %s for update""" % (doc.doctype, '%s'), parent, as_dict=1)[0]
|
||||
where name = %s for update""" % (doc.doctype, '%s'), parent, as_dict=1)[0]
|
||||
|
||||
# set parent lft, rgt
|
||||
frappe.db.sql("""update `tab{0}` set rgt = rgt + %s
|
||||
|
|
@ -156,7 +153,7 @@ def rebuild_tree(doctype, parent_field):
|
|||
.where(
|
||||
(column == "") | (column.isnull())
|
||||
)
|
||||
.orderby(Replace(table.name, '_', ''), order=Order.asc)
|
||||
.orderby(table.name, order=Order.asc)
|
||||
.select(table.name)
|
||||
).run()
|
||||
|
||||
|
|
@ -179,7 +176,7 @@ def rebuild_node(doctype, parent, left, parent_field):
|
|||
column = getattr(table, parent_field)
|
||||
|
||||
result = (
|
||||
frappe.qb.from_(table).where(column == parent).select(table.name).orderby(Replace(table.name, '_', ''), order=Order.asc)
|
||||
frappe.qb.from_(table).where(column == parent).select(table.name)
|
||||
).run()
|
||||
|
||||
for r in result:
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue