Bug #80679 Python Connector escape() errors out on dates
Submitted: 9 Mar 2016 22:13 Modified: 10 Mar 2016 7:47
Reporter: Sam King Email Updates:
Status: Verified Impact on me:
None 
Category:Connector / Python Severity:S3 (Non-critical)
Version:2.1.3 OS:Ubuntu
Assigned to: CPU Architecture:Any
Tags: escape

[9 Mar 2016 22:13] Sam King
Description:
The MySQLConverter.escape() method does not work for dates.  Creating a db connection and then calling conn.converter.escape(datetime.datetime.now().date()) throws the error "TypeError: an integer is required".  This happens because dates have a replace method that is different from the replace method on string objects.

The docstring on that method indicates that it should return the value if the value is not a string.  If the code were modified to do that (eg, changing the "else" to an "elif isinstance(value, basestring)" or something like that), it would work.

How to repeat:
Create a DB connection.

Call conn.converter.escape(datetime.datetime.now().date().

Suggested fix:
Modify MySQLConverter.escape() so that it will only do the value = value.replace() logic when value is a string.  

Alternately, add date types to NUMERIC_TYPES (though that might have unintended consequences elsewhere) or add a special case in escape() for date types.
[10 Mar 2016 7:47] Chiranjeevi Battula
Hello  Sam King,

Thank you for the bug report.
Verified this behavior on MySQL Connector/Python 2.1.3.

Thanks,
Chiranjeevi.
[10 Mar 2016 7:48] Chiranjeevi Battula
Output:
Traceback (most recent call last):
  File "D:\Python\80679.py", line 9, in <module>
    dbconn.converter.escape(datetime.datetime.now().date())
  File "C:\Python27\lib\site-packages\mysql\connector\conversion.py", line 145, in escape
    value = value.replace('\\', '\\\\')
TypeError: an integer is required