Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: bigint validation (backport #25733) #25821

Merged
merged 2 commits into from
Apr 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion frappe/core/doctype/doctype/test_doctype.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from frappe.cache_manager import clear_doctype_cache
from frappe.core.doctype.doctype.doctype import (
CannotIndexedError,
DocType,
DoctypeLinkError,
HiddenAndMandatoryWithoutDefaultError,
IllegalMandatoryError,
Expand Down Expand Up @@ -719,7 +720,7 @@ def new_doctype(
custom: bool = True,
default: str | None = None,
**kwargs,
):
) -> "DocType":
if not name:
# Test prefix is required to avoid coverage
name = "Test " + "".join(random.sample(string.ascii_lowercase, 10))
Expand Down
3 changes: 3 additions & 0 deletions frappe/model/base_document.py
Original file line number Diff line number Diff line change
Expand Up @@ -933,6 +933,9 @@ def _validate_length(self):
self.throw_length_exceeded_error(df, max_length, value)

elif column_type in ("int", "bigint", "smallint"):
if cint(df.get("length")) > 11: # We implicitl switch to bigint for >11
column_type = "bigint"

max_length = max_positive_value[column_type]

if abs(cint(value)) > max_length:
Expand Down
11 changes: 11 additions & 0 deletions frappe/tests/test_db_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,17 @@ def check_unique_indexes(self, doctype: str, field: str):
len(indexes), 1, msg=f"There should be 1 index on {doctype}.{field}, found {indexes}"
)

@run_only_if(db_type_is.MARIADB) # postgres uses invalid type for <=15
def test_bigint_conversion(self):
doctype = new_doctype(fields=[{"fieldname": "int_field", "fieldtype": "Int"}]).insert()

with self.assertRaises(frappe.CharacterLengthExceededError):
frappe.get_doc(doctype=doctype.name, int_field=2**62 - 1).insert()

doctype.fields[0].length = 14
doctype.save()
frappe.get_doc(doctype=doctype.name, int_field=2**62 - 1).insert()

@run_only_if(db_type_is.MARIADB)
def test_unique_index_on_install(self):
"""Only one unique index should be added"""
Expand Down
Loading