From 9731dc5db0bf46d1ed540599b5b76eea737445a1 Mon Sep 17 00:00:00 2001 From: Balamurali M Date: Wed, 3 Jul 2024 07:18:42 +0530 Subject: [PATCH] fix(MariaDBVariable): Remove bool option Does not work correctly with ansible's mysql_variables module "ON" and "OFF" work fine - Make innodb_print_all_deadlocks str, not bool --- press/fixtures/mariadb_variable.json | 158 +++++++++--------- .../database_server_mariadb_variable.json | 9 +- .../database_server_mariadb_variable.py | 5 +- .../test_database_server_mariadb_variable.py | 6 +- .../mariadb_variable/mariadb_variable.json | 4 +- .../mariadb_variable/mariadb_variable.py | 4 +- 6 files changed, 88 insertions(+), 98 deletions(-) diff --git a/press/fixtures/mariadb_variable.json b/press/fixtures/mariadb_variable.json index 8461e4f4af..3819baf637 100644 --- a/press/fixtures/mariadb_variable.json +++ b/press/fixtures/mariadb_variable.json @@ -132,181 +132,181 @@ "skippable": 0 }, { - "datatype": "Str", - "default_value": "", - "doc_section": "replication-and-binary-log", + "datatype": "Int", + "default_value": "5120", + "doc_section": "server", "docstatus": 0, "doctype": "MariaDB Variable", "dynamic": 1, - "modified": "2023-08-03 14:20:47.702196", - "name": "expire_logs_days", - "set_on_new_servers": 0, + "modified": "2023-09-22 08:38:16.807229", + "name": "tmp_disk_table_size", + "set_on_new_servers": 1, "skippable": 0 }, { "datatype": "Str", - "default_value": "37", - "doc_section": "innodb", - "docstatus": 0, - "doctype": "MariaDB Variable", - "dynamic": 1, - "modified": "2023-09-15 15:21:13.086214", - "name": "innodb_old_blocks_pct", - "set_on_new_servers": 0, - "skippable": 0 - }, - { - "datatype": "Int", - "default_value": null, - "doc_section": "innodb", + "default_value": "5", + "doc_section": "server", "docstatus": 0, "doctype": "MariaDB Variable", "dynamic": 1, - "modified": "2023-06-15 14:41:36.038646", - "name": "innodb_buffer_pool_size", - "set_on_new_servers": 0, + "modified": "2024-03-05 12:55:47.689706", + "name": "extra_max_connections", + "set_on_new_servers": 1, "skippable": 0 }, { "datatype": "Str", - "default_value": "/var/lib/mysql/mysql-bin", - "doc_section": "replication-and-binary-log", + "default_value": "3307", + "doc_section": "server", "docstatus": 0, "doctype": "MariaDB Variable", "dynamic": 0, - "modified": "2023-06-15 14:41:09.156699", - "name": "log_bin", - "set_on_new_servers": 0, - "skippable": 1 + "modified": "2024-03-05 12:55:54.950776", + "name": "extra_port", + "set_on_new_servers": 1, + "skippable": 0 }, { "datatype": "Str", - "default_value": "5000", - "doc_section": "innodb", + "default_value": "100", + "doc_section": "server", "docstatus": 0, "doctype": "MariaDB Variable", "dynamic": 1, - "modified": "2023-09-22 14:02:04.157025", - "name": "innodb_old_blocks_time", + "modified": "2023-12-17 20:05:35.338733", + "name": "max_connections", "set_on_new_servers": 1, "skippable": 0 }, { - "datatype": "Int", - "default_value": "512", + "datatype": "Str", + "default_value": null, "doc_section": "server", "docstatus": 0, "doctype": "MariaDB Variable", "dynamic": 1, - "modified": "2023-09-22 08:38:25.704420", - "name": "max_allowed_packet", - "set_on_new_servers": 1, + "modified": "2024-01-12 14:21:03.949888", + "name": "max_user_connections", + "set_on_new_servers": 0, "skippable": 0 }, { - "datatype": "Int", - "default_value": "5120", - "doc_section": "server", + "datatype": "Str", + "default_value": null, + "doc_section": "replication-and-binary-log", "docstatus": 0, "doctype": "MariaDB Variable", "dynamic": 1, - "modified": "2023-09-22 08:38:16.807229", - "name": "tmp_disk_table_size", - "set_on_new_servers": 1, + "modified": "2024-03-05 12:59:31.069472", + "name": "binlog_expire_logs_seconds", + "set_on_new_servers": 0, "skippable": 0 }, { - "datatype": "Str", - "default_value": "5", + "datatype": "Int", + "default_value": "32", "doc_section": "server", "docstatus": 0, "doctype": "MariaDB Variable", "dynamic": 1, - "modified": "2024-03-05 12:55:47.689706", - "name": "extra_max_connections", - "set_on_new_servers": 1, + "modified": "2024-06-12 10:30:47.403256", + "name": "max_heap_table_size", + "set_on_new_servers": 0, "skippable": 0 }, { "datatype": "Str", - "default_value": "3307", - "doc_section": "server", + "default_value": "", + "doc_section": "replication-and-binary-log", "docstatus": 0, "doctype": "MariaDB Variable", - "dynamic": 0, - "modified": "2024-03-05 12:55:54.950776", - "name": "extra_port", - "set_on_new_servers": 1, + "dynamic": 1, + "modified": "2023-08-03 14:20:47.702196", + "name": "expire_logs_days", + "set_on_new_servers": 0, "skippable": 0 }, { "datatype": "Str", - "default_value": "100", - "doc_section": "server", + "default_value": "37", + "doc_section": "innodb", "docstatus": 0, "doctype": "MariaDB Variable", "dynamic": 1, - "modified": "2023-12-17 20:05:35.338733", - "name": "max_connections", - "set_on_new_servers": 1, + "modified": "2023-09-15 15:21:13.086214", + "name": "innodb_old_blocks_pct", + "set_on_new_servers": 0, "skippable": 0 }, { - "datatype": "Str", + "datatype": "Int", "default_value": null, - "doc_section": "server", + "doc_section": "innodb", "docstatus": 0, "doctype": "MariaDB Variable", "dynamic": 1, - "modified": "2024-01-12 14:21:03.949888", - "name": "max_user_connections", + "modified": "2023-06-15 14:41:36.038646", + "name": "innodb_buffer_pool_size", "set_on_new_servers": 0, "skippable": 0 }, { "datatype": "Str", - "default_value": null, + "default_value": "/var/lib/mysql/mysql-bin", "doc_section": "replication-and-binary-log", "docstatus": 0, "doctype": "MariaDB Variable", - "dynamic": 1, - "modified": "2024-03-05 12:59:31.069472", - "name": "binlog_expire_logs_seconds", + "dynamic": 0, + "modified": "2023-06-15 14:41:09.156699", + "name": "log_bin", "set_on_new_servers": 0, - "skippable": 0 + "skippable": 1 }, { "datatype": "Str", - "default_value": "3600", - "doc_section": "server", + "default_value": "5000", + "doc_section": "innodb", "docstatus": 0, "doctype": "MariaDB Variable", "dynamic": 1, - "modified": "2024-03-28 15:23:30.635417", - "name": "max_statement_time", + "modified": "2023-09-22 14:02:04.157025", + "name": "innodb_old_blocks_time", "set_on_new_servers": 1, "skippable": 0 }, { "datatype": "Int", - "default_value": "32", + "default_value": "512", "doc_section": "server", "docstatus": 0, "doctype": "MariaDB Variable", "dynamic": 1, - "modified": "2024-06-12 10:30:47.403256", - "name": "max_heap_table_size", - "set_on_new_servers": 0, + "modified": "2023-09-22 08:38:25.704420", + "name": "max_allowed_packet", + "set_on_new_servers": 1, "skippable": 0 }, { - "datatype": "Bool", + "datatype": "Str", + "default_value": "3600", + "doc_section": "server", + "docstatus": 0, + "doctype": "MariaDB Variable", + "dynamic": 1, + "modified": "2024-03-28 15:23:30.635417", + "name": "max_statement_time", + "set_on_new_servers": 1, + "skippable": 0 + }, + { + "datatype": "Str", "default_value": null, "doc_section": "innodb", "docstatus": 0, "doctype": "MariaDB Variable", "dynamic": 1, - "modified": "2024-07-02 19:20:23.150723", + "modified": "2024-07-03 07:13:23.014958", "name": "innodb_print_all_deadlocks", "set_on_new_servers": 0, "skippable": 0 diff --git a/press/press/doctype/database_server_mariadb_variable/database_server_mariadb_variable.json b/press/press/doctype/database_server_mariadb_variable/database_server_mariadb_variable.json index faa93d2278..e352580d00 100644 --- a/press/press/doctype/database_server_mariadb_variable/database_server_mariadb_variable.json +++ b/press/press/doctype/database_server_mariadb_variable/database_server_mariadb_variable.json @@ -10,7 +10,6 @@ "mariadb_variable", "value_int", "value_str", - "value_bool", "value_float", "skip", "persist" @@ -41,12 +40,6 @@ "in_list_view": 1, "label": "Skip" }, - { - "default": "0", - "fieldname": "value_bool", - "fieldtype": "Check", - "label": "Value Bool" - }, { "default": "0", "fieldname": "persist", @@ -64,7 +57,7 @@ "index_web_pages_for_search": 1, "istable": 1, "links": [], - "modified": "2023-06-01 10:55:14.041364", + "modified": "2024-07-03 07:15:03.695917", "modified_by": "Administrator", "module": "Press", "name": "Database Server MariaDB Variable", diff --git a/press/press/doctype/database_server_mariadb_variable/database_server_mariadb_variable.py b/press/press/doctype/database_server_mariadb_variable/database_server_mariadb_variable.py index a3c60011ba..e8c1c2dc5e 100644 --- a/press/press/doctype/database_server_mariadb_variable/database_server_mariadb_variable.py +++ b/press/press/doctype/database_server_mariadb_variable/database_server_mariadb_variable.py @@ -25,7 +25,6 @@ class DatabaseServerMariaDBVariable(Document): parenttype: DF.Data persist: DF.Check skip: DF.Check - value_bool: DF.Check value_float: DF.Float value_int: DF.Int value_str: DF.Data | None @@ -36,11 +35,11 @@ def datatype(self) -> str: return frappe.db.get_value("MariaDB Variable", self.mariadb_variable, "datatype") @property - def value_fields(self): + def value_fields(self) -> list[str]: return list(filter(lambda x: x.startswith("value_"), self.as_dict().keys())) @property - def value_field(self): + def value_field(self) -> str: """Return the first value field that has a value""" for f in self.value_fields: if self.get(f): diff --git a/press/press/doctype/database_server_mariadb_variable/test_database_server_mariadb_variable.py b/press/press/doctype/database_server_mariadb_variable/test_database_server_mariadb_variable.py index 2b61605c12..7cb8f4968a 100644 --- a/press/press/doctype/database_server_mariadb_variable/test_database_server_mariadb_variable.py +++ b/press/press/doctype/database_server_mariadb_variable/test_database_server_mariadb_variable.py @@ -41,7 +41,7 @@ def test_only_one_datatype_value_can_be_set_for_one_mariadb_variable(self): { "mariadb_variable": "innodb_buffer_pool_size", "value_int": 1000, - "value_bool": True, + "value_str": str(1000 * 1024), }, ) with self.assertRaises(frappe.ValidationError): @@ -63,7 +63,7 @@ def test_value_field_set_matches_datatype(self): "mariadb_system_variables", { "mariadb_variable": "innodb_buffer_pool_size", - "value_bool": 1000, # seeing if only value is checked and not the field + "value_str": "1000", # seeing if only value is checked and not the field }, ) with self.assertRaises(frappe.ValidationError): @@ -79,7 +79,7 @@ def test_value_field_set_matches_datatype(self): server.save() def test_only_skippable_variables_can_be_skipped(self): - """Test that only bool variables can be skipped""" + """Test that only skippable variables can be skipped""" server = create_test_database_server() server.append( "mariadb_system_variables", diff --git a/press/press/doctype/mariadb_variable/mariadb_variable.json b/press/press/doctype/mariadb_variable/mariadb_variable.json index 8308f1c8fd..c9ef0da264 100644 --- a/press/press/doctype/mariadb_variable/mariadb_variable.json +++ b/press/press/doctype/mariadb_variable/mariadb_variable.json @@ -30,7 +30,7 @@ "fieldname": "datatype", "fieldtype": "Select", "label": "Datatype", - "options": "Int\nBool\nFloat\nStr", + "options": "Int\nFloat\nStr", "reqd": 1 }, { @@ -65,7 +65,7 @@ ], "index_web_pages_for_search": 1, "links": [], - "modified": "2023-09-22 08:36:43.526135", + "modified": "2024-07-03 07:14:39.263413", "modified_by": "Administrator", "module": "Press", "name": "MariaDB Variable", diff --git a/press/press/doctype/mariadb_variable/mariadb_variable.py b/press/press/doctype/mariadb_variable/mariadb_variable.py index 8f71d28b8b..e324357edf 100644 --- a/press/press/doctype/mariadb_variable/mariadb_variable.py +++ b/press/press/doctype/mariadb_variable/mariadb_variable.py @@ -16,7 +16,7 @@ class MariaDBVariable(Document): if TYPE_CHECKING: from frappe.types import DF - datatype: DF.Literal["Int", "Bool", "Float", "Str"] + datatype: DF.Literal["Int", "Float", "Str"] default_value: DF.Data | None doc_section: DF.Literal["server", "replication-and-binary-log", "innodb"] dynamic: DF.Check @@ -32,8 +32,6 @@ def get_default_value(self): return int(value) case "Float": return float(value) - case "Bool": - return bool(value) return value @frappe.whitelist()