Django

Code

Changeset 8802

Show
Ignore:
Timestamp:
09/01/08 12:48:39 (3 months ago)
Author:
jacob
Message:

Fixed #8354: the MySQL backend no longer raises a cryptic error. Instead, 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.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/django/db/backends/mysql/base.py

    r8782 r8802  
    173173 
    174174    def value_to_db_datetime(self, value): 
    175         # MySQL doesn't support microseconds 
    176175        if value is None: 
    177176            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 
    178183        return unicode(value.replace(microsecond=0)) 
    179184 
    180185    def value_to_db_time(self, value): 
    181         # MySQL doesn't support microseconds 
    182186        if value is None: 
    183187            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 
    184194        return unicode(value.replace(microsecond=0)) 
    185195 
  • django/trunk/tests/regressiontests/datatypes/models.py

    r8801 r8802  
    8484 
    8585"""} 
     86 
     87# Regression test for #8354: the MySQL backend should raise an error if given 
     88# a timezone-aware datetime object. 
     89if 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() 
     95Traceback (most recent call last): 
     96    .... 
     97ValueError: MySQL backend does not support timezone-aware datetimes. 
     98"""