From 044d7a1e5c23307c86cf9b0efb46928a885faf7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaros=C5=82aw=20Sadzi=C5=84ski?= Date: Thu, 10 Nov 2022 18:37:31 +0100 Subject: [PATCH] (core) Throwing error in PHONE_FORMAT when value is not a string Summary: Adding type check in the PHONE_FORMAT function. Default conversion to string doesn't work well for floats. Test Plan: Updated Reviewers: dsagal Reviewed By: dsagal Subscribers: dsagal Differential Revision: https://phab.getgrist.com/D3701 --- sandbox/grist/functions/text.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/sandbox/grist/functions/text.py b/sandbox/grist/functions/text.py index 5af5c34889..746089dff2 100644 --- a/sandbox/grist/functions/text.py +++ b/sandbox/grist/functions/text.py @@ -336,9 +336,19 @@ def PHONE_FORMAT(value, country=None, format=None): # pylint: disable=redefined u'tel:+33-2-34-56-78-90' >>> PHONE_FORMAT("tel:+1-234-567-8901", country="US", format="*") u'+12345678901' + >>> PHONE_FORMAT(33234567890) + Traceback (most recent call last): + ... + TypeError: Phone number must be a text value. \ +If formatting a value from a Numeric column, convert that column to Text first. """ if not value: return value + + if not isinstance(value, six.string_types): + raise TypeError("Phone number must be a text value. " + + "If formatting a value from a Numeric column, convert that column to Text first.") + if format is None and country in output_formats: format = country country = None