<commit_before># Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
# MIT License. See license.txt

from __future__ import unicode_literals, print_function

import frappe
import json
from frappe.model import no_value_fields, table_fields
from frappe.utils.password import rename_password_field
from frappe.model.utils.user_settings import update_user_settings_data, sync_user_settings


def rename_field(doctype, old_fieldname, new_fieldname):
	"""This functions assumes that doctype is already synced"""

	meta = frappe.get_meta(doctype, cached=False)
	new_field = meta.get_field(new_fieldname)
	if not new_field:
		print("rename_field: " + (new_fieldname) + " not found in " + doctype)
		return

	if new_field.fieldtype in table_fields:
		# change parentfield of table mentioned in options
		frappe.db.sql("""update `tab%s` set parentfield=%s
			where parentfield=%s""" % (new_field.options.split("\n")[0], "%s", "%s"),
			(new_fieldname, old_fieldname))<commit_msg>fix(rename_field): skip if old fieldname does not exist<commit_after># Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
# MIT License. See license.txt

from __future__ import unicode_literals, print_function

import frappe
import json
from frappe.model import no_value_fields, table_fields
from frappe.utils.password import rename_password_field
from frappe.model.utils.user_settings import update_user_settings_data, sync_user_settings


def rename_field(doctype, old_fieldname, new_fieldname):
	"""This functions assumes that doctype is already synced"""

	meta = frappe.get_meta(doctype, cached=False)
	new_field = meta.get_field(new_fieldname)
	if not new_field:
		print("rename_field: " + (new_fieldname) + " not found in " + doctype)
		return

	if not frappe.db.has_column(doctype, old_fieldname):
		# never had the field?
		return

	if new_field.fieldtype in table_fields:
		# change parentfield of table mentioned in options
		frappe.db.sql("""update `tab%s` set parentfield=%s
			where parentfield=%s""" % (new_field.options.split("\n")[0], "%s", "%s"),
			(new_fieldname, old_fieldname))

{'fraction_non_alphanumeric': 0.09952380952380953, 'fraction_numerical': 0.004761904761904762, 'mean_word_length': 5.888524590163934, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4313174', 'n_tokens_mistral': 715, 'n_tokens_neox': 680, 'n_words': 187}