From c3409c818eba2e0d4e30bf27a8bd8aabadd4c566 Mon Sep 17 00:00:00 2001 From: Shadrak Gurupnor <30501401+shadrak98@users.noreply.github.com> Date: Sat, 15 Jan 2022 20:15:01 +0530 Subject: [PATCH] fix: patch for validating options field (#15565) * fix: patch for validating options field * fix: reorder patch execution * refactor: reduce queries for patching * refactor: change patch name and license Co-authored-by: Ankush Menat --- frappe/patches.txt | 1 + .../remove_invalid_options_for_data_fields.py | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) create mode 100644 frappe/patches/v13_0/remove_invalid_options_for_data_fields.py diff --git a/frappe/patches.txt b/frappe/patches.txt index af7e4d6e3f..4231a59466 100644 --- a/frappe/patches.txt +++ b/frappe/patches.txt @@ -123,6 +123,7 @@ frappe.patches.v12_0.remove_parent_and_parenttype_from_print_formats frappe.patches.v12_0.remove_example_email_thread_notify execute:from frappe.desk.page.setup_wizard.install_fixtures import update_genders;update_genders() frappe.patches.v12_0.set_correct_url_in_files +frappe.patches.v13_0.remove_invalid_options_for_data_fields frappe.patches.v13_0.website_theme_custom_scss frappe.patches.v13_0.make_user_type frappe.patches.v13_0.set_existing_dashboard_charts_as_public diff --git a/frappe/patches/v13_0/remove_invalid_options_for_data_fields.py b/frappe/patches/v13_0/remove_invalid_options_for_data_fields.py new file mode 100644 index 0000000000..90e4b3c5c6 --- /dev/null +++ b/frappe/patches/v13_0/remove_invalid_options_for_data_fields.py @@ -0,0 +1,17 @@ +# Copyright (c) 2022, Frappe and Contributors +# License: MIT. See LICENSE + + +import frappe +from frappe.model import data_field_options + + +def execute(): + custom_field = frappe.qb.DocType('Custom Field') + (frappe.qb + .update(custom_field) + .set(custom_field.options, None) + .where( + (custom_field.fieldtype == "Data") + & (custom_field.options.notin(data_field_options))) + ).run()