From 30f00fd5f3ffba649a1f959ec7a8a75fb89b1f74 Mon Sep 17 00:00:00 2001 From: Ankush Menat Date: Fri, 29 Mar 2024 21:59:35 +0530 Subject: [PATCH 1/3] fix: invlaid integer validations for biging closes https://github.com/frappe/frappe/issues/25566 --- frappe/core/doctype/doctype/test_doctype.py | 3 ++- frappe/model/base_document.py | 3 +++ frappe/tests/test_db_update.py | 10 ++++++++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/frappe/core/doctype/doctype/test_doctype.py b/frappe/core/doctype/doctype/test_doctype.py index 464996d3e9..8a481eb11f 100644 --- a/frappe/core/doctype/doctype/test_doctype.py +++ b/frappe/core/doctype/doctype/test_doctype.py @@ -10,6 +10,7 @@ import frappe from frappe.cache_manager import clear_doctype_cache from frappe.core.doctype.doctype.doctype import ( CannotIndexedError, + DocType, DoctypeLinkError, HiddenAndMandatoryWithoutDefaultError, IllegalMandatoryError, @@ -782,7 +783,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)) diff --git a/frappe/model/base_document.py b/frappe/model/base_document.py index 3a7520fd1c..dbda0133d7 100644 --- a/frappe/model/base_document.py +++ b/frappe/model/base_document.py @@ -983,6 +983,9 @@ class BaseDocument: 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: diff --git a/frappe/tests/test_db_update.py b/frappe/tests/test_db_update.py index 68a22e0de2..a6f6a095dd 100644 --- a/frappe/tests/test_db_update.py +++ b/frappe/tests/test_db_update.py @@ -99,6 +99,16 @@ class TestDBUpdate(FrappeTestCase): len(indexes), 1, msg=f"There should be 1 index on {doctype}.{field}, found {indexes}" ) + 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""" From b493bfe7c22dd64dbe805a986b77f2fe9f32b6c9 Mon Sep 17 00:00:00 2001 From: Ankush Menat Date: Fri, 29 Mar 2024 22:01:27 +0530 Subject: [PATCH 2/3] fix(DX): annotate chainable methods with `Self` return --- frappe/model/document.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/frappe/model/document.py b/frappe/model/document.py index c0a6047f98..f202cfe4ce 100644 --- a/frappe/model/document.py +++ b/frappe/model/document.py @@ -26,6 +26,8 @@ from frappe.utils.data import get_absolute_url, get_datetime, get_timedelta, get from frappe.utils.global_search import update_global_search if TYPE_CHECKING: + from typing_extensions import Self + from frappe.core.doctype.docfield.docfield import DocField @@ -144,7 +146,7 @@ class Document(BaseDocument): def is_locked(self): return file_lock.lock_exists(self.get_signature()) - def load_from_db(self): + def load_from_db(self) -> "Self": """Load document and children from database and create properties from fields""" self.flags.ignore_children = True @@ -204,7 +206,7 @@ class Document(BaseDocument): return self - def reload(self): + def reload(self) -> "Self": """Reload document from database""" return self.load_from_db() @@ -248,7 +250,7 @@ class Document(BaseDocument): ignore_mandatory=None, set_name=None, set_child_names=True, - ) -> "Document": + ) -> "Self": """Insert the document in the database (as a new document). This will check for user permissions and execute `before_insert`, `validate`, `on_update`, `after_insert` methods if they are written. @@ -333,11 +335,11 @@ class Document(BaseDocument): if self.creation and self.is_locked: raise frappe.DocumentLockedError - def save(self, *args, **kwargs): + def save(self, *args, **kwargs) -> "Self": """Wrapper for _save""" return self._save(*args, **kwargs) - def _save(self, ignore_permissions=None, ignore_version=None) -> "Document": + def _save(self, ignore_permissions=None, ignore_version=None) -> "Self": """Save the current document in the database in the **DocType**'s table or `tabSingles` (for single types). From eef9c2c8cc3a10676c5179a2f3648da8310ada81 Mon Sep 17 00:00:00 2001 From: Ankush Menat Date: Sat, 6 Apr 2024 10:45:50 +0530 Subject: [PATCH 3/3] refactor!: Better Integer handling - Remove length: it makes no difference, it's for ZEROFILL only. - Switch to tinyint for checkboxes in mysql and smallint on postgres. - Use `int` instead of `bigint` by default. --- frappe/database/mariadb/database.py | 8 +- frappe/database/mariadb/framework_mariadb.sql | 176 +++++++++--------- frappe/database/mariadb/schema.py | 4 +- frappe/database/postgres/database.py | 2 +- frappe/tests/test_db_update.py | 4 +- 5 files changed, 97 insertions(+), 97 deletions(-) diff --git a/frappe/database/mariadb/database.py b/frappe/database/mariadb/database.py index b7deed266e..1fbf335180 100644 --- a/frappe/database/mariadb/database.py +++ b/frappe/database/mariadb/database.py @@ -161,11 +161,11 @@ class MariaDBDatabase(MariaDBConnectionUtil, MariaDBExceptionUtil, Database): self.db_type = "mariadb" self.type_map = { "Currency": ("decimal", "21,9"), - "Int": ("int", "11"), + "Int": ("int", None), "Long Int": ("bigint", "20"), "Float": ("decimal", "21,9"), "Percent": ("decimal", "21,9"), - "Check": ("int", "1"), + "Check": ("tinyint", None), "Small Text": ("text", ""), "Long Text": ("longtext", ""), "Code": ("longtext", ""), @@ -288,7 +288,7 @@ class MariaDBDatabase(MariaDBConnectionUtil, MariaDBExceptionUtil, Database): `name` VARCHAR(255) NOT NULL, `fieldname` VARCHAR(140) NOT NULL, `password` TEXT NOT NULL, - `encrypted` INT(1) NOT NULL DEFAULT 0, + `encrypted` TINYINT NOT NULL DEFAULT 0, PRIMARY KEY (`doctype`, `name`, `fieldname`) ) ENGINE=InnoDB ROW_FORMAT=DYNAMIC CHARACTER SET=utf8mb4 COLLATE=utf8mb4_unicode_ci""" ) @@ -303,7 +303,7 @@ class MariaDBDatabase(MariaDBConnectionUtil, MariaDBExceptionUtil, Database): content text, fulltext(content), route varchar({self.VARCHAR_LEN}), - published int(1) not null default 0, + published TINYINT not null default 0, unique `doctype_name` (doctype, name)) COLLATE=utf8mb4_unicode_ci ENGINE=MyISAM diff --git a/frappe/database/mariadb/framework_mariadb.sql b/frappe/database/mariadb/framework_mariadb.sql index d9f5c9edc5..002570350f 100644 --- a/frappe/database/mariadb/framework_mariadb.sql +++ b/frappe/database/mariadb/framework_mariadb.sql @@ -13,61 +13,61 @@ CREATE TABLE `tabDocField` ( `modified` datetime(6) DEFAULT NULL, `modified_by` varchar(255) DEFAULT NULL, `owner` varchar(255) DEFAULT NULL, - `docstatus` int(1) NOT NULL DEFAULT 0, + `docstatus` tinyint NOT NULL DEFAULT 0, `parent` varchar(255) DEFAULT NULL, `parentfield` varchar(255) DEFAULT NULL, `parenttype` varchar(255) DEFAULT NULL, - `idx` int(8) NOT NULL DEFAULT 0, + `idx` int NOT NULL DEFAULT 0, `fieldname` varchar(255) DEFAULT NULL, `label` varchar(255) DEFAULT NULL, `oldfieldname` varchar(255) DEFAULT NULL, `fieldtype` varchar(255) DEFAULT NULL, `oldfieldtype` varchar(255) DEFAULT NULL, `options` text, - `search_index` int(1) NOT NULL DEFAULT 0, - `show_dashboard` int(1) NOT NULL DEFAULT 0, - `hidden` int(1) NOT NULL DEFAULT 0, - `set_only_once` int(1) NOT NULL DEFAULT 0, - `allow_in_quick_entry` int(1) NOT NULL DEFAULT 0, - `print_hide` int(1) NOT NULL DEFAULT 0, - `report_hide` int(1) NOT NULL DEFAULT 0, - `reqd` int(1) NOT NULL DEFAULT 0, - `bold` int(1) NOT NULL DEFAULT 0, - `in_global_search` int(1) NOT NULL DEFAULT 0, - `collapsible` int(1) NOT NULL DEFAULT 0, - `unique` int(1) NOT NULL DEFAULT 0, - `no_copy` int(1) NOT NULL DEFAULT 0, - `allow_on_submit` int(1) NOT NULL DEFAULT 0, - `show_preview_popup` int(1) NOT NULL DEFAULT 0, + `search_index` tinyint NOT NULL DEFAULT 0, + `show_dashboard` tinyint NOT NULL DEFAULT 0, + `hidden` tinyint NOT NULL DEFAULT 0, + `set_only_once` tinyint NOT NULL DEFAULT 0, + `allow_in_quick_entry` tinyint NOT NULL DEFAULT 0, + `print_hide` tinyint NOT NULL DEFAULT 0, + `report_hide` tinyint NOT NULL DEFAULT 0, + `reqd` tinyint NOT NULL DEFAULT 0, + `bold` tinyint NOT NULL DEFAULT 0, + `in_global_search` tinyint NOT NULL DEFAULT 0, + `collapsible` tinyint NOT NULL DEFAULT 0, + `unique` tinyint NOT NULL DEFAULT 0, + `no_copy` tinyint NOT NULL DEFAULT 0, + `allow_on_submit` tinyint NOT NULL DEFAULT 0, + `show_preview_popup` tinyint NOT NULL DEFAULT 0, `trigger` varchar(255) DEFAULT NULL, `collapsible_depends_on` text, `mandatory_depends_on` text, `read_only_depends_on` text, `depends_on` text, - `permlevel` int(11) NOT NULL DEFAULT 0, - `ignore_user_permissions` int(1) NOT NULL DEFAULT 0, + `permlevel` int NOT NULL DEFAULT 0, + `ignore_user_permissions` tinyint NOT NULL DEFAULT 0, `width` varchar(255) DEFAULT NULL, `print_width` varchar(255) DEFAULT NULL, - `columns` int(11) NOT NULL DEFAULT 0, + `columns` int NOT NULL DEFAULT 0, `default` text, `description` text, - `in_list_view` int(1) NOT NULL DEFAULT 0, - `fetch_if_empty` int(1) NOT NULL DEFAULT 0, - `in_filter` int(1) NOT NULL DEFAULT 0, - `remember_last_selected_value` int(1) NOT NULL DEFAULT 0, - `ignore_xss_filter` int(1) NOT NULL DEFAULT 0, - `print_hide_if_no_value` int(1) NOT NULL DEFAULT 0, - `allow_bulk_edit` int(1) NOT NULL DEFAULT 0, - `in_standard_filter` int(1) NOT NULL DEFAULT 0, - `in_preview` int(1) NOT NULL DEFAULT 0, - `read_only` int(1) NOT NULL DEFAULT 0, + `in_list_view` tinyint NOT NULL DEFAULT 0, + `fetch_if_empty` tinyint NOT NULL DEFAULT 0, + `in_filter` tinyint NOT NULL DEFAULT 0, + `remember_last_selected_value` tinyint NOT NULL DEFAULT 0, + `ignore_xss_filter` tinyint NOT NULL DEFAULT 0, + `print_hide_if_no_value` tinyint NOT NULL DEFAULT 0, + `allow_bulk_edit` tinyint NOT NULL DEFAULT 0, + `in_standard_filter` tinyint NOT NULL DEFAULT 0, + `in_preview` tinyint NOT NULL DEFAULT 0, + `read_only` tinyint NOT NULL DEFAULT 0, `precision` varchar(255) DEFAULT NULL, `max_height` varchar(10) DEFAULT NULL, - `length` int(11) NOT NULL DEFAULT 0, - `translatable` int(1) NOT NULL DEFAULT 0, - `hide_border` int(1) NOT NULL DEFAULT 0, - `hide_days` int(1) NOT NULL DEFAULT 0, - `hide_seconds` int(1) NOT NULL DEFAULT 0, + `length` int NOT NULL DEFAULT 0, + `translatable` tinyint NOT NULL DEFAULT 0, + `hide_border` tinyint NOT NULL DEFAULT 0, + `hide_days` tinyint NOT NULL DEFAULT 0, + `hide_seconds` tinyint NOT NULL DEFAULT 0, PRIMARY KEY (`name`), KEY `parent` (`parent`), KEY `label` (`label`), @@ -87,27 +87,27 @@ CREATE TABLE `tabDocPerm` ( `modified` datetime(6) DEFAULT NULL, `modified_by` varchar(255) DEFAULT NULL, `owner` varchar(255) DEFAULT NULL, - `docstatus` int(1) NOT NULL DEFAULT 0, + `docstatus` tinyint NOT NULL DEFAULT 0, `parent` varchar(255) DEFAULT NULL, `parentfield` varchar(255) DEFAULT NULL, `parenttype` varchar(255) DEFAULT NULL, - `idx` int(8) NOT NULL DEFAULT 0, - `permlevel` int(11) DEFAULT '0', + `idx` int NOT NULL DEFAULT 0, + `permlevel` int DEFAULT '0', `role` varchar(255) DEFAULT NULL, `match` varchar(255) DEFAULT NULL, - `read` int(1) NOT NULL DEFAULT 1, - `write` int(1) NOT NULL DEFAULT 1, - `create` int(1) NOT NULL DEFAULT 1, - `submit` int(1) NOT NULL DEFAULT 0, - `cancel` int(1) NOT NULL DEFAULT 0, - `delete` int(1) NOT NULL DEFAULT 1, - `amend` int(1) NOT NULL DEFAULT 0, - `report` int(1) NOT NULL DEFAULT 1, - `export` int(1) NOT NULL DEFAULT 1, - `import` int(1) NOT NULL DEFAULT 0, - `share` int(1) NOT NULL DEFAULT 1, - `print` int(1) NOT NULL DEFAULT 1, - `email` int(1) NOT NULL DEFAULT 1, + `read` tinyint NOT NULL DEFAULT 1, + `write` tinyint NOT NULL DEFAULT 1, + `create` tinyint NOT NULL DEFAULT 1, + `submit` tinyint NOT NULL DEFAULT 0, + `cancel` tinyint NOT NULL DEFAULT 0, + `delete` tinyint NOT NULL DEFAULT 1, + `amend` tinyint NOT NULL DEFAULT 0, + `report` tinyint NOT NULL DEFAULT 1, + `export` tinyint NOT NULL DEFAULT 1, + `import` tinyint NOT NULL DEFAULT 0, + `share` tinyint NOT NULL DEFAULT 1, + `print` tinyint NOT NULL DEFAULT 1, + `email` tinyint NOT NULL DEFAULT 1, PRIMARY KEY (`name`), KEY `parent` (`parent`) ) ENGINE=InnoDB ROW_FORMAT=DYNAMIC CHARACTER SET=utf8mb4 COLLATE=utf8mb4_unicode_ci; @@ -123,11 +123,11 @@ CREATE TABLE `tabDocType Action` ( `modified` datetime(6) DEFAULT NULL, `modified_by` varchar(140) COLLATE utf8mb4_unicode_ci DEFAULT NULL, `owner` varchar(140) COLLATE utf8mb4_unicode_ci DEFAULT NULL, - `docstatus` int(1) NOT NULL DEFAULT 0, + `docstatus` tinyint NOT NULL DEFAULT 0, `parent` varchar(140) COLLATE utf8mb4_unicode_ci DEFAULT NULL, `parentfield` varchar(140) COLLATE utf8mb4_unicode_ci DEFAULT NULL, `parenttype` varchar(140) COLLATE utf8mb4_unicode_ci DEFAULT NULL, - `idx` int(8) NOT NULL DEFAULT 0, + `idx` int NOT NULL DEFAULT 0, `label` varchar(140) COLLATE utf8mb4_unicode_ci DEFAULT NULL, `group` varchar(140) COLLATE utf8mb4_unicode_ci DEFAULT NULL, `action_type` varchar(140) COLLATE utf8mb4_unicode_ci DEFAULT NULL, @@ -147,11 +147,11 @@ CREATE TABLE `tabDocType Link` ( `modified` datetime(6) DEFAULT NULL, `modified_by` varchar(140) COLLATE utf8mb4_unicode_ci DEFAULT NULL, `owner` varchar(140) COLLATE utf8mb4_unicode_ci DEFAULT NULL, - `docstatus` int(1) NOT NULL DEFAULT 0, + `docstatus` tinyint NOT NULL DEFAULT 0, `parent` varchar(140) COLLATE utf8mb4_unicode_ci DEFAULT NULL, `parentfield` varchar(140) COLLATE utf8mb4_unicode_ci DEFAULT NULL, `parenttype` varchar(140) COLLATE utf8mb4_unicode_ci DEFAULT NULL, - `idx` int(8) NOT NULL DEFAULT 0, + `idx` int NOT NULL DEFAULT 0, `group` varchar(140) COLLATE utf8mb4_unicode_ci DEFAULT NULL, `link_doctype` varchar(140) COLLATE utf8mb4_unicode_ci DEFAULT NULL, `link_fieldname` varchar(140) COLLATE utf8mb4_unicode_ci DEFAULT NULL, @@ -170,15 +170,15 @@ CREATE TABLE `tabDocType` ( `modified` datetime(6) DEFAULT NULL, `modified_by` varchar(255) DEFAULT NULL, `owner` varchar(255) DEFAULT NULL, - `docstatus` int(1) NOT NULL DEFAULT 0, - `idx` int(8) NOT NULL DEFAULT 0, + `docstatus` tinyint NOT NULL DEFAULT 0, + `idx` int NOT NULL DEFAULT 0, `search_fields` varchar(255) DEFAULT NULL, - `issingle` int(1) NOT NULL DEFAULT 0, - `is_virtual` int(1) NOT NULL DEFAULT 0, - `is_tree` int(1) NOT NULL DEFAULT 0, - `istable` int(1) NOT NULL DEFAULT 0, - `editable_grid` int(1) NOT NULL DEFAULT 1, - `track_changes` int(1) NOT NULL DEFAULT 0, + `issingle` tinyint NOT NULL DEFAULT 0, + `is_virtual` tinyint NOT NULL DEFAULT 0, + `is_tree` tinyint NOT NULL DEFAULT 0, + `istable` tinyint NOT NULL DEFAULT 0, + `editable_grid` tinyint NOT NULL DEFAULT 1, + `track_changes` tinyint NOT NULL DEFAULT 0, `module` varchar(255) DEFAULT NULL, `restrict_to_domain` varchar(255) DEFAULT NULL, `app` varchar(255) DEFAULT NULL, @@ -191,17 +191,17 @@ CREATE TABLE `tabDocType` ( `sort_order` varchar(255) DEFAULT NULL, `description` text, `colour` varchar(255) DEFAULT NULL, - `read_only` int(1) NOT NULL DEFAULT 0, - `in_create` int(1) NOT NULL DEFAULT 0, - `menu_index` int(11) DEFAULT NULL, + `read_only` tinyint NOT NULL DEFAULT 0, + `in_create` tinyint NOT NULL DEFAULT 0, + `menu_index` int DEFAULT NULL, `parent_node` varchar(255) DEFAULT NULL, `smallicon` varchar(255) DEFAULT NULL, - `allow_copy` int(1) NOT NULL DEFAULT 0, - `allow_rename` int(1) NOT NULL DEFAULT 0, - `allow_import` int(1) NOT NULL DEFAULT 0, - `hide_toolbar` int(1) NOT NULL DEFAULT 0, - `track_seen` int(1) NOT NULL DEFAULT 0, - `max_attachments` int(11) NOT NULL DEFAULT 0, + `allow_copy` tinyint NOT NULL DEFAULT 0, + `allow_rename` tinyint NOT NULL DEFAULT 0, + `allow_import` tinyint NOT NULL DEFAULT 0, + `hide_toolbar` tinyint NOT NULL DEFAULT 0, + `track_seen` tinyint NOT NULL DEFAULT 0, + `max_attachments` int NOT NULL DEFAULT 0, `print_outline` varchar(255) DEFAULT NULL, `document_type` varchar(255) DEFAULT NULL, `icon` varchar(255) DEFAULT NULL, @@ -211,22 +211,22 @@ CREATE TABLE `tabDocType` ( `_last_update` varchar(32) DEFAULT NULL, `engine` varchar(20) DEFAULT 'InnoDB', `default_print_format` varchar(255) DEFAULT NULL, - `is_submittable` int(1) NOT NULL DEFAULT 0, - `show_name_in_global_search` int(1) NOT NULL DEFAULT 0, + `is_submittable` tinyint NOT NULL DEFAULT 0, + `show_name_in_global_search` tinyint NOT NULL DEFAULT 0, `_user_tags` varchar(255) DEFAULT NULL, - `custom` int(1) NOT NULL DEFAULT 0, - `beta` int(1) NOT NULL DEFAULT 0, - `has_web_view` int(1) NOT NULL DEFAULT 0, - `allow_guest_to_view` int(1) NOT NULL DEFAULT 0, + `custom` tinyint NOT NULL DEFAULT 0, + `beta` tinyint NOT NULL DEFAULT 0, + `has_web_view` tinyint NOT NULL DEFAULT 0, + `allow_guest_to_view` tinyint NOT NULL DEFAULT 0, `route` varchar(255) DEFAULT NULL, `is_published_field` varchar(255) DEFAULT NULL, `website_search_field` varchar(255) DEFAULT NULL, - `email_append_to` int(1) NOT NULL DEFAULT 0, + `email_append_to` tinyint NOT NULL DEFAULT 0, `subject_field` varchar(255) DEFAULT NULL, `sender_field` varchar(255) DEFAULT NULL, - `show_title_field_in_link` int(1) NOT NULL DEFAULT 0, + `show_title_field_in_link` tinyint NOT NULL DEFAULT 0, `migration_hash` varchar(255) DEFAULT NULL, - `translated_doctype` int(1) NOT NULL DEFAULT 0, + `translated_doctype` tinyint NOT NULL DEFAULT 0, PRIMARY KEY (`name`) ) ENGINE=InnoDB ROW_FORMAT=DYNAMIC CHARACTER SET=utf8mb4 COLLATE=utf8mb4_unicode_ci; @@ -237,7 +237,7 @@ CREATE TABLE `tabDocType` ( DROP TABLE IF EXISTS `tabSeries`; CREATE TABLE `tabSeries` ( `name` varchar(100), - `current` int(10) NOT NULL DEFAULT 0, + `current` int NOT NULL DEFAULT 0, PRIMARY KEY(`name`) ) ENGINE=InnoDB ROW_FORMAT=DYNAMIC CHARACTER SET=utf8mb4 COLLATE=utf8mb4_unicode_ci; @@ -280,7 +280,7 @@ CREATE TABLE `__Auth` ( `name` VARCHAR(255) NOT NULL, `fieldname` VARCHAR(140) NOT NULL, `password` TEXT NOT NULL, - `encrypted` INT(1) NOT NULL DEFAULT 0, + `encrypted` tinyint NOT NULL DEFAULT 0, PRIMARY KEY (`doctype`, `name`, `fieldname`) ) ENGINE=InnoDB ROW_FORMAT=DYNAMIC CHARACTER SET=utf8mb4 COLLATE=utf8mb4_unicode_ci; @@ -295,16 +295,16 @@ CREATE TABLE `tabFile` ( `modified` datetime(6) DEFAULT NULL, `modified_by` varchar(255) DEFAULT NULL, `owner` varchar(255) DEFAULT NULL, - `docstatus` int(1) NOT NULL DEFAULT 0, + `docstatus` tinyint NOT NULL DEFAULT 0, `parent` varchar(255) DEFAULT NULL, `parentfield` varchar(255) DEFAULT NULL, `parenttype` varchar(255) DEFAULT NULL, - `idx` int(8) NOT NULL DEFAULT 0, + `idx` int NOT NULL DEFAULT 0, `file_name` varchar(255) DEFAULT NULL, `file_url` varchar(255) DEFAULT NULL, `module` varchar(255) DEFAULT NULL, `attached_to_name` varchar(255) DEFAULT NULL, - `file_size` int(11) NOT NULL DEFAULT 0, + `file_size` int NOT NULL DEFAULT 0, `attached_to_doctype` varchar(255) DEFAULT NULL, PRIMARY KEY (`name`), KEY `parent` (`parent`), @@ -323,11 +323,11 @@ CREATE TABLE `tabDefaultValue` ( `modified` datetime(6) DEFAULT NULL, `modified_by` varchar(255) DEFAULT NULL, `owner` varchar(255) DEFAULT NULL, - `docstatus` int(1) NOT NULL DEFAULT 0, + `docstatus` tinyint NOT NULL DEFAULT 0, `parent` varchar(255) DEFAULT NULL, `parentfield` varchar(255) DEFAULT NULL, `parenttype` varchar(255) DEFAULT NULL, - `idx` int(8) NOT NULL DEFAULT 0, + `idx` int NOT NULL DEFAULT 0, `defvalue` text, `defkey` varchar(255) DEFAULT NULL, PRIMARY KEY (`name`), diff --git a/frappe/database/mariadb/schema.py b/frappe/database/mariadb/schema.py index d1ec513026..fd5c5a103b 100644 --- a/frappe/database/mariadb/schema.py +++ b/frappe/database/mariadb/schema.py @@ -59,8 +59,8 @@ class MariaDBTable(DBTable): modified datetime(6), modified_by varchar({varchar_len}), owner varchar({varchar_len}), - docstatus int(1) not null default '0', - idx int(8) not null default '0', + docstatus tinyint not null default '0', + idx int not null default '0', {additional_definitions}) ENGINE={engine} ROW_FORMAT=DYNAMIC diff --git a/frappe/database/postgres/database.py b/frappe/database/postgres/database.py index aa64b74cb7..f5e94244d8 100644 --- a/frappe/database/postgres/database.py +++ b/frappe/database/postgres/database.py @@ -125,7 +125,7 @@ class PostgresDatabase(PostgresExceptionUtil, Database): self.db_type = "postgres" self.type_map = { "Currency": ("decimal", "21,9"), - "Int": ("bigint", None), + "Int": ("int", None), "Long Int": ("bigint", None), "Float": ("decimal", "21,9"), "Percent": ("decimal", "21,9"), diff --git a/frappe/tests/test_db_update.py b/frappe/tests/test_db_update.py index a6f6a095dd..b0ee59fba6 100644 --- a/frappe/tests/test_db_update.py +++ b/frappe/tests/test_db_update.py @@ -35,7 +35,7 @@ class TestDBUpdate(FrappeTestCase): ) default = field_def.default if field_def.default is not None else fallback_default - self.assertEqual(fieldtype, table_column.type) + self.assertIn(fieldtype, table_column.type, msg=f"Types not matching for {fieldname}") self.assertIn(cstr(table_column.default) or "NULL", [cstr(default), f"'{default}'"]) def test_index_and_unique_constraints(self): @@ -167,7 +167,7 @@ class TestDBUpdate(FrappeTestCase): def get_fieldtype_from_def(field_def): fieldtuple = frappe.db.type_map.get(field_def.fieldtype, ("", 0)) fieldtype = fieldtuple[0] - if fieldtype in ("varchar", "datetime", "int"): + if fieldtype in ("varchar", "datetime"): fieldtype += f"({field_def.length or fieldtuple[1]})" return fieldtype