Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #8354: the MySQL backend no longer raises a cryptic error. Inst…

…ead, it raises a less-cryptic error. Obiously this isn't a perfect solution by any means, but it'll do until we can revisit timezone handling in the future.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@8802 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit e545058ba94f5f5736a5db82e6ba5883d8071485 1 parent 1520629
Jacob Kaplan-Moss authored September 01, 2008
14  django/db/backends/mysql/base.py
@@ -172,15 +172,25 @@ def sql_flush(self, style, tables, sequences):
172 172
             return []
173 173
 
174 174
     def value_to_db_datetime(self, value):
175  
-        # MySQL doesn't support microseconds
176 175
         if value is None:
177 176
             return None
  177
+        
  178
+        # MySQL doesn't support tz-aware datetimes
  179
+        if value.tzinfo is not None:
  180
+            raise ValueError("MySQL backend does not support timezone-aware datetimes.")
  181
+
  182
+        # MySQL doesn't support microseconds
178 183
         return unicode(value.replace(microsecond=0))
179 184
 
180 185
     def value_to_db_time(self, value):
181  
-        # MySQL doesn't support microseconds
182 186
         if value is None:
183 187
             return None
  188
+            
  189
+        # MySQL doesn't support tz-aware datetimes
  190
+        if value.tzinfo is not None:
  191
+            raise ValueError("MySQL backend does not support timezone-aware datetimes.")
  192
+        
  193
+        # MySQL doesn't support microseconds
184 194
         return unicode(value.replace(microsecond=0))
185 195
 
186 196
     def year_lookup_bounds(self, value):
13  tests/regressiontests/datatypes/models.py
@@ -83,3 +83,16 @@ def __str__(self):
83 83
 []
84 84
 
85 85
 """}
  86
+
  87
+# Regression test for #8354: the MySQL backend should raise an error if given
  88
+# a timezone-aware datetime object.
  89
+if settings.DATABASE_ENGINE == 'mysql':
  90
+    __test__['API_TESTS'] += """
  91
+>>> from django.utils import tzinfo 
  92
+>>> dt = datetime.datetime(2008, 8, 31, 16, 20, tzinfo=tzinfo.FixedOffset(0)) 
  93
+>>> d = Donut(name='Bear claw', consumed_at=dt) 
  94
+>>> d.save()
  95
+Traceback (most recent call last):
  96
+    ....
  97
+ValueError: MySQL backend does not support timezone-aware datetimes.
  98
+"""

0 notes on commit e545058

Please sign in to comment.
Something went wrong with that request. Please try again.