Bug #74336 Connector/Python Django Backend doesn't support SafeText
Submitted: 12 Oct 2014 11:18 Modified: 17 Mar 2015 17:24
Reporter: zulan zulan Email Updates:
Status: Closed Impact on me:
None 
Category:Connector / Python Severity:S2 (Serious)
Version:2.0.1 OS:Any
Assigned to: Peeyush Gupta CPU Architecture:Any
Tags: Django

[12 Oct 2014 11:18] zulan zulan
Description:
In some cases a SafeText object can be passed to a model filter and then end up in a query. The mysql connector fails to convert these parameters in MySQLConverter / to_mysql (Python 'safetext' cannot be converted to a MySQL type)

How to repeat:
Unfortunately setting up a minimal example is rather complex. I encountered it in connection with static-precompiler.

Suggested fix:
My first guess would be a MySQLConverterDjango that provides these django specific conversions.

Django itsself uses these encoders in the django.db.backends.base.DatabaseWrapper:

        conn.encoders[SafeText] = conn.encoders[six.text_type]
        conn.encoders[SafeBytes] = conn.encoders[bytes]
[27 Nov 2014 8:19] Peeyush Gupta
Verified.

Thanks for the bug report :)
[17 Mar 2015 17:24] Paul DuBois
Noted in 2.0.4 changelog.

The Django backend sometimes failed to properly convert SafeText
objects, which then appeared in queries.
[30 Mar 2015 15:58] Paul DuBois
Noted in 2.1.2 changelog.