From b8c51b13e2f89e231c19bc94b32fb7e8251557ca Mon Sep 17 00:00:00 2001 From: Gavin D'souza Date: Mon, 30 Aug 2021 13:45:30 +0530 Subject: [PATCH] fix: Revert to using cast_fieldtype in BaseDocument.cast * reference: revert Breaking Change - https://github.com/frappe/frappe/pull/13989#discussion_r695624003 * Show deprecation warning unless `show_warning` is unset --- frappe/model/base_document.py | 4 ++-- frappe/utils/data.py | 14 +++++++------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/frappe/model/base_document.py b/frappe/model/base_document.py index 815dd27002..1e3ef53fbd 100644 --- a/frappe/model/base_document.py +++ b/frappe/model/base_document.py @@ -9,7 +9,7 @@ from frappe.model.utils.link_count import notify_link_count from frappe.modules import load_doctype_module from frappe.model import display_fieldtypes from frappe.utils import (cint, flt, now, cstr, strip_html, - sanitize_html, sanitize_email, cast) + sanitize_html, sanitize_email, cast_fieldtype) from frappe.utils.html_utils import unescape_html max_positive_value = { @@ -969,7 +969,7 @@ class BaseDocument(object): return self.cast(val, df) def cast(self, value, df): - return cast(df.fieldtype, value) + return cast_fieldtype(df.fieldtype, value, show_warning=False) def _extract_images_from_text_editor(self): from frappe.core.doctype.file.file import extract_images_from_doc diff --git a/frappe/utils/data.py b/frappe/utils/data.py index 4a25ad997a..4e972c0189 100644 --- a/frappe/utils/data.py +++ b/frappe/utils/data.py @@ -506,13 +506,13 @@ def has_common(l1, l2): """Returns truthy value if there are common elements in lists l1 and l2""" return set(l1) & set(l2) -def cast_fieldtype(fieldtype, value): - # TODO: Add DeprecationWarning for this util - message = ( - "Function `frappe.utils.data.cast` has been deprecated in favour" - " of `frappe.utils.data.cast`. Use the newer util for safer type casting. " - ) - secho(message, fg="yellow") +def cast_fieldtype(fieldtype, value, show_warning=True): + if show_warning: + message = ( + "Function `frappe.utils.data.cast` has been deprecated in favour" + " of `frappe.utils.data.cast`. Use the newer util for safer type casting." + ) + secho(message, fg="yellow") if fieldtype in ("Currency", "Float", "Percent"): value = flt(value)