fix: set_next_val function for sequences

postgres uses t & f, mariadb uses 0 & 1 for is_value_used
This commit is contained in:
phot0n 2022-03-05 23:30:08 +05:30
parent 93fbace331
commit 15ae019b12
2 changed files with 7 additions and 3 deletions

View file

@ -69,8 +69,12 @@ def set_next_val(
is_val_used :bool = False
) -> None:
is_val_used = 0 if not is_val_used else 1
if not is_val_used:
is_val_used = 0 if db.db_type == "mariadb" else "f"
else:
is_val_used = 1 if db.db_type == "mariadb" else "t"
if db.db_type == "postgres":
db.sql(f"SELECT SETVAL(\'\"{scrub(doctype_name + slug)}\"\', {next_val}, {is_val_used})")
db.sql(f"SELECT SETVAL('\"{scrub(doctype_name + slug)}\"', {next_val}, '{is_val_used}')")
else:
db.sql(f"SELECT SETVAL(`{scrub(doctype_name + slug)}`, {next_val}, {is_val_used})")

View file

@ -329,7 +329,7 @@ def validate_name(doctype: str, name: Union[int, str], case: Optional[str] = Non
set_next_val(doctype, name, is_val_used=True)
return name
frappe.throw("Invalid name type (integer) for varchar name column")
frappe.throw(_("Invalid name type (integer) for varchar name column"), frappe.NameError)
if name.startswith("New "+doctype):
frappe.throw(_("There were some errors setting the name, please contact the administrator"), frappe.NameError)