diff options
| author | Malcolm Tredinnick <malcolm.tredinnick@gmail.com> | 2008-11-16 08:50:06 +0000 |
|---|---|---|
| committer | Malcolm Tredinnick <malcolm.tredinnick@gmail.com> | 2008-11-16 08:50:06 +0000 |
| commit | 1418da7ee417dfc85cb2ebd034b95d21fe2ea015 (patch) | |
| tree | 5ab77d2ef10a45a5d23ed544cab9b9a84474e6b5 /django | |
| parent | 9d0bacebd2d0fc2b3581dac9acdc631338387921 (diff) | |
Fixed #6052 -- Worked around a bug in MySQLdb with regards to handling
SafeUnicode (handle SafeString similarly, just to be safe). Based on a patch
from sfllaw.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@9467 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django')
| -rw-r--r-- | django/db/backends/mysql/base.py | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/django/db/backends/mysql/base.py b/django/db/backends/mysql/base.py index bda4f8f596..2fb1988f7a 100644 --- a/django/db/backends/mysql/base.py +++ b/django/db/backends/mysql/base.py @@ -29,6 +29,7 @@ from django.db.backends.mysql.client import DatabaseClient from django.db.backends.mysql.creation import DatabaseCreation from django.db.backends.mysql.introspection import DatabaseIntrospection from django.db.backends.mysql.validation import DatabaseValidation +from django.utils.safestring import SafeString, SafeUnicode # Raise exceptions for database warnings if DEBUG is on from django.conf import settings @@ -39,12 +40,11 @@ if settings.DEBUG: DatabaseError = Database.DatabaseError IntegrityError = Database.IntegrityError -# MySQLdb-1.2.1 supports the Python boolean type, and only uses datetime -# module for time-related columns; older versions could have used mx.DateTime -# or strings if there were no datetime module. However, MySQLdb still returns -# TIME columns as timedelta -- they are more like timedelta in terms of actual -# behavior as they are signed and include days -- and Django expects time, so -# we still need to override that. +# MySQLdb-1.2.1 returns TIME columns as timedelta -- they are more like +# timedelta in terms of actual behavior as they are signed and include days -- +# and Django expects time, so we still need to override that. We also need to +# add special handling for SafeUnicode and SafeString as MySQLdb's type +# checking is too tight to catch those (see Django ticket #6052). django_conversions = conversions.copy() django_conversions.update({ FIELD_TYPE.TIME: util.typecast_time, @@ -174,7 +174,7 @@ class DatabaseOperations(BaseDatabaseOperations): def value_to_db_datetime(self, value): if value is None: return None - + # MySQL doesn't support tz-aware datetimes if value.tzinfo is not None: raise ValueError("MySQL backend does not support timezone-aware datetimes.") @@ -185,11 +185,11 @@ class DatabaseOperations(BaseDatabaseOperations): def value_to_db_time(self, value): if value is None: return None - + # MySQL doesn't support tz-aware datetimes if value.tzinfo is not None: raise ValueError("MySQL backend does not support timezone-aware datetimes.") - + # MySQL doesn't support microseconds return unicode(value.replace(microsecond=0)) @@ -260,6 +260,8 @@ class DatabaseWrapper(BaseDatabaseWrapper): kwargs['port'] = int(settings.DATABASE_PORT) kwargs.update(self.options) self.connection = Database.connect(**kwargs) + self.connection.encoders[SafeUnicode] = self.connection.encoders[unicode] + self.connection.encoders[SafeString] = self.connection.encoders[str] cursor = CursorWrapper(self.connection.cursor()) return cursor |
