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
This commit is contained in:
Gavin D'souza 2021-08-30 13:45:30 +05:30
parent ed6533f737
commit b8c51b13e2
2 changed files with 9 additions and 9 deletions

View file

@ -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

View file

@ -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)