Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor!: override_doctype -> Must extend base class #26152

Merged
merged 2 commits into from Apr 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
22 changes: 15 additions & 7 deletions frappe/model/base_document.py
Expand Up @@ -87,16 +87,24 @@ def import_controller(doctype):

module_path = None
class_overrides = frappe.get_hooks("override_doctype_class")

module = load_doctype_module(doctype, module_name)
classname = doctype.replace(" ", "").replace("-", "")
class_ = getattr(module, classname, None)

if class_overrides and class_overrides.get(doctype):
import_path = class_overrides[doctype][-1]
module_path, classname = import_path.rsplit(".", 1)
module = frappe.get_module(module_path)

else:
module = load_doctype_module(doctype, module_name)
classname = doctype.replace(" ", "").replace("-", "")
module_path, custom_classname = import_path.rsplit(".", 1)
custom_module = frappe.get_module(module_path)
custom_class_ = getattr(custom_module, custom_classname, None)
if not issubclass(custom_class_, class_):
original_class_path = frappe.bold(f"{class_.__module__}.{class_.__name__}")
frappe.throw(
f"{doctype}: {frappe.bold(import_path)} must be a subclass of {original_class_path}",
title=_("Invalid Override"),
)
class_ = custom_class_

class_ = getattr(module, classname, None)
if class_ is None:
raise ImportError(
doctype
Expand Down
8 changes: 1 addition & 7 deletions frappe/utils/data.py
Expand Up @@ -1779,13 +1779,7 @@ def get_url(uri: str | None = None, full_address: bool = False) -> str:

port = frappe.conf.http_port or frappe.conf.webserver_port

if (
not frappe.conf.restart_supervisor_on_update
and not frappe.conf.restart_systemd_on_update
and host_name
and not url_contains_port(host_name)
and port
):
if host_name and not url_contains_port(host_name) and port:
host_name = host_name + ":" + str(port)

return urljoin(host_name, uri) if uri else host_name
Expand Down