Validation error - query args escape_unicode error

when try add child table and make validation on it i got this error

Traceback (most recent call last):
  File "/home/frappe/frappe-bench/apps/frappe/frappe/desk/form/save.py", line 22, in savedocs
    doc.save()
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py", line 259, in save
    return self._save(*args, **kwargs)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py", line 293, in _save
    self.run_before_save_methods()
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py", line 862, in run_before_save_methods
    self.run_method("validate")
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py", line 758, in run_method
    out = Document.hook(fn)(self, *args, **kwargs)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py", line 1027, in composer
    return composed(self, method, *args, **kwargs)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py", line 1010, in runner
    add_to_return_value(self, fn(self, *args, **kwargs))
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py", line 752, in <lambda>
    fn = lambda self, *args, **kwargs: getattr(self, method)(*args, **kwargs)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/desk/doctype/event/event.py", line 22, in validate
    self.validate_overlap()
  File "/home/frappe/frappe-bench/apps/frappe/frappe/desk/doctype/event/event.py", line 43, in validate_overlap
    validate_overlap_for(self, "Event", "teacher")
  File "/home/frappe/frappe-bench/apps/frappe/frappe/desk/utils.py", line 17, in validate_overlap_for
    existing = get_overlap_for(doc, doctype, fieldname, value)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/desk/utils.py", line 42, in get_overlap_for
    }, as_dict=True)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/database.py", line 166, in sql
    self._cursor.execute(query, values)
  File "/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/pymysql/cursors.py", line 168, in execute
    query = self.mogrify(query, args)
  File "/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/pymysql/cursors.py", line 147, in mogrify
    query = query % self._escape_args(args, conn)
  File "/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/pymysql/cursors.py", line 127, in _escape_args
    return dict((key, conn.literal(val)) for (key, val) in args.items())
  File "/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/pymysql/cursors.py", line 127, in <genexpr>
    return dict((key, conn.literal(val)) for (key, val) in args.items())
  File "/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/pymysql/connections.py", line 469, in literal
    return self.escape(obj, self.encoders)
  File "/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/pymysql/connections.py", line 462, in escape
    return converters.escape_item(obj, self.charset, mapping=mapping)
  File "/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/pymysql/converters.py", line 25, in escape_item
    val = encoder(val, charset, mapping)
  File "/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/pymysql/converters.py", line 40, in escape_sequence
    quoted = escape_item(item, charset, mapping)
  File "/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/pymysql/converters.py", line 27, in escape_item
    val = encoder(val, mapping)
  File "/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/pymysql/converters.py", line 118, in escape_unicode
    return u"'%s'" % _escape_unicode(value)
  File "/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/pymysql/converters.py", line 73, in _escape_unicode
    return value.translate(_escape_table)
AttributeError: 'teacher' object has no attribute 'translate'

Traceback (most recent call last):
  File "/home/frappe/frappe-bench/apps/frappe/frappe/app.py", line 62, in application
    response = frappe.handler.handle()
  File "/home/frappe/frappe-bench/apps/frappe/frappe/handler.py", line 22, in handle
    data = execute_cmd(cmd)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/handler.py", line 53, in execute_cmd
    return frappe.call(method, **frappe.form_dict)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/__init__.py", line 939, in call
    return fn(*args, **newargs)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/desk/form/save.py", line 22, in savedocs
    doc.save()
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py", line 259, in save
    return self._save(*args, **kwargs)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py", line 293, in _save
    self.run_before_save_methods()
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py", line 862, in run_before_save_methods
    self.run_method("validate")
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py", line 758, in run_method
    out = Document.hook(fn)(self, *args, **kwargs)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py", line 1027, in composer
    return composed(self, method, *args, **kwargs)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py", line 1010, in runner
    add_to_return_value(self, fn(self, *args, **kwargs))
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py", line 752, in <lambda>
    fn = lambda self, *args, **kwargs: getattr(self, method)(*args, **kwargs)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/desk/doctype/event/event.py", line 22, in validate
    self.validate_overlap()
  File "/home/frappe/frappe-bench/apps/frappe/frappe/desk/doctype/event/event.py", line 43, in validate_overlap
    validate_overlap_for(self, "Event", "teacher")
  File "/home/frappe/frappe-bench/apps/frappe/frappe/desk/utils.py", line 17, in validate_overlap_for
    existing = get_overlap_for(doc, doctype, fieldname, value)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/desk/utils.py", line 42, in get_overlap_for
    }, as_dict=True)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/database.py", line 166, in sql
    self._cursor.execute(query, values)
  File "/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/pymysql/cursors.py", line 168, in execute
    query = self.mogrify(query, args)
  File "/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/pymysql/cursors.py", line 147, in mogrify
    query = query % self._escape_args(args, conn)
  File "/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/pymysql/cursors.py", line 127, in _escape_args
    return dict((key, conn.literal(val)) for (key, val) in args.items())
  File "/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/pymysql/cursors.py", line 127, in <genexpr>
    return dict((key, conn.literal(val)) for (key, val) in args.items())
  File "/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/pymysql/connections.py", line 469, in literal
    return self.escape(obj, self.encoders)
  File "/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/pymysql/connections.py", line 462, in escape
    return converters.escape_item(obj, self.charset, mapping=mapping)
  File "/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/pymysql/converters.py", line 25, in escape_item
    val = encoder(val, charset, mapping)
  File "/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/pymysql/converters.py", line 40, in escape_sequence
    quoted = escape_item(item, charset, mapping)
  File "/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/pymysql/converters.py", line 27, in escape_item
    val = encoder(val, mapping)
  File "/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/pymysql/converters.py", line 118, in escape_unicode
    return u"'%s'" % _escape_unicode(value)
  File "/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/pymysql/converters.py", line 73, in _escape_unicode
    return value.translate(_escape_table)
AttributeError: 'teacher' object has no attribute 'translate'

@clarkej thanks for editing but if you have any edia about this error

This notes an indentation error may be the issue and how to check for that https://stackoverflow.com/questions/11685936/python-attributeerror-object-has-no-attribute

Some print statements might help you debug here too?

Dear @clarkej
Thanks for your support but this not an indentation error because when i make the same validation code on normal custom filed it’s working but when i make it on field in child table i got this error

Dear Community ,
@clarkej
any update about this issue i need to know if this is a system bug or error in the code

The error arises in this code

File “/home/frappe/frappe-bench/apps/frappe/frappe/desk/doctype/event/event.py”, line 22, in validate
self.validate_overlap()
File “/home/frappe/frappe-bench/apps/frappe/frappe/desk/doctype/event/event.py”, line 43, in validate_overlap
validate_overlap_for(self, “Event”, “teacher”)

hence your post here Overlap validation

It seems the query is malformed due to encoding?

Perhaps confirm tabTeacher in fact has this Alaa_Badri

“AttributeError: ‘teacher’ object has no attribute ‘translate’”