'Check if change in varchar length isn\'t truncating the columns'

def validate(self):

    if self.is_new():
        return
    self.get_columns_from_db()
    columns = [frappe._dict({u'fieldname': f, u'fieldtype': u'Data'}) for f in standard_varchar_columns]
    columns += self.columns.values()
    for col in columns:
        if (len(col.fieldname) >= 64):
            frappe.throw(_(u'Fieldname    is    limited    to    64    characters    ({0})').format(frappe.bold(col.fieldname)))
        if ((col.fieldtype in type_map) and (type_map[col.fieldtype][0] == u'varchar')):
            new_length = (cint(col.length) or cint(varchar_len))
            if (not (1 <= new_length <= 1000)):
                frappe.throw(_(u'Length    of    {0}    should    be    between    1    and    1000').format(col.fieldname))
            try:
                max_length = frappe.db.sql(u'select    max(char_length(`{fieldname}`))    from    `tab{doctype}`'.format(fieldname=col.fieldname, doctype=self.doctype))
            except MySQLdb.OperationalError as e:
                if (e.args[0] == 1054):
                    continue
                else:
                    raise
            if (max_length and (max_length[0][0] > new_length)):
                current_type = self.current_columns[col.fieldname][u'type']
                current_length = re.findall(u'varchar\\(([\\d]+)\\)', current_type)
                if (not current_length):
                    continue
                current_length = current_length[0]
                if (col.fieldname in self.columns):
                    self.columns[col.fieldname].length = current_length
                frappe.msgprint(_(u"Reverting    length    to    {0}    for    '{1}'    in    '{2}';    Setting    the    length    as    {3}    will    cause    truncation    of    data.").format(current_length, col.fieldname, self.doctype, new_length))
