From 176d6d2d069b918d959a3240c17d153cc4312f54 Mon Sep 17 00:00:00 2001 From: Gavin D'souza Date: Tue, 31 Aug 2021 13:07:22 +0530 Subject: [PATCH] fix: Check if input is str is_invalid_date_string This is sort of a breaking change? Because if an int/dict/list/tuple was passed instead of a str, object doesnt have .startswith (AttributeError) would be raised instead of just returning None. --- frappe/utils/data.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/frappe/utils/data.py b/frappe/utils/data.py index 62eb6790e0..5cd41226da 100644 --- a/frappe/utils/data.py +++ b/frappe/utils/data.py @@ -18,10 +18,10 @@ DATETIME_FORMAT = DATE_FORMAT + " " + TIME_FORMAT def is_invalid_date_string(date_string): # dateutil parser does not agree with dates like "0001-01-01" or "0000-00-00" - return (not date_string) or (date_string or "").startswith(("0001-01-01", "0000-00-00")) + return not isinstance(date_string, str) or ((not date_string) or (date_string or "").startswith(("0001-01-01", "0000-00-00"))) # datetime functions -def getdate(string_date=None): +def getdate(string_date: str = None): """ Converts string date (yyyy-mm-dd) to datetime.date object. If no input is provided, current date is returned.