Python 3 issue in re

Python 3 interprets string literals as Unicode strings, and therefore \d is treated as an escaped Unicode character.

Declare RegEx pattern as a raw string instead by prepending r or double escape \d
This commit is contained in:
Joseph Marie Alba 2021-05-16 05:52:05 +08:00 committed by GitHub
parent d84d02349c
commit c795a70897
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -283,7 +283,7 @@ def append_number_if_name_exists(doctype, value, fieldname="name", separator="-"
filters.update({fieldname: value})
exists = frappe.db.exists(doctype, filters)
regex = "^{value}{separator}\d+$".format(value=re.escape(value), separator=separator)
regex = "^{value}{separator}\\d+$".format(value=re.escape(value), separator=separator)
if exists:
last = frappe.db.sql("""SELECT `{fieldname}` FROM `tab{doctype}`