Made the oracle backend throw the same ValueError as the mysql backend when a timezone-aware datetime is passed in. This fixes a datatypes test failure.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@14544 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
e0e347c2d3
commit
87a8046f90
|
@ -292,11 +292,24 @@ WHEN (new.%(col_name)s IS NULL)
|
||||||
return "%sTABLESPACE %s" % ((inline and "USING INDEX " or ""),
|
return "%sTABLESPACE %s" % ((inline and "USING INDEX " or ""),
|
||||||
self.quote_name(tablespace))
|
self.quote_name(tablespace))
|
||||||
|
|
||||||
|
def value_to_db_datetime(self, value):
|
||||||
|
# Oracle doesn't support tz-aware datetimes
|
||||||
|
if getattr(value, 'tzinfo', None) is not None:
|
||||||
|
raise ValueError("Oracle backend does not support timezone-aware datetimes.")
|
||||||
|
|
||||||
|
return super(DatabaseOperations, self).value_to_db_datetime(value)
|
||||||
|
|
||||||
def value_to_db_time(self, value):
|
def value_to_db_time(self, value):
|
||||||
if value is None:
|
if value is None:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
if isinstance(value, basestring):
|
if isinstance(value, basestring):
|
||||||
return datetime.datetime(*(time.strptime(value, '%H:%M:%S')[:6]))
|
return datetime.datetime(*(time.strptime(value, '%H:%M:%S')[:6]))
|
||||||
|
|
||||||
|
# Oracle doesn't support tz-aware datetimes
|
||||||
|
if value.tzinfo is not None:
|
||||||
|
raise ValueError("Oracle backend does not support timezone-aware datetimes.")
|
||||||
|
|
||||||
return datetime.datetime(1900, 1, 1, value.hour, value.minute,
|
return datetime.datetime(1900, 1, 1, value.hour, value.minute,
|
||||||
value.second, value.microsecond)
|
value.second, value.microsecond)
|
||||||
|
|
||||||
|
|
|
@ -76,8 +76,8 @@ class DataTypesTestCase(TestCase):
|
||||||
|
|
||||||
@skipIfDBFeature('supports_timezones')
|
@skipIfDBFeature('supports_timezones')
|
||||||
def test_error_on_timezone(self):
|
def test_error_on_timezone(self):
|
||||||
"""Regression test for #8354: the MySQL backend should raise an error
|
"""Regression test for #8354: the MySQL and Oracle backends should raise
|
||||||
if given a timezone-aware datetime object."""
|
an error if given a timezone-aware datetime object."""
|
||||||
dt = datetime.datetime(2008, 8, 31, 16, 20, tzinfo=tzinfo.FixedOffset(0))
|
dt = datetime.datetime(2008, 8, 31, 16, 20, tzinfo=tzinfo.FixedOffset(0))
|
||||||
d = Donut(name='Bear claw', consumed_at=dt)
|
d = Donut(name='Bear claw', consumed_at=dt)
|
||||||
self.assertRaises(ValueError, d.save)
|
self.assertRaises(ValueError, d.save)
|
||||||
|
|
Loading…
Reference in New Issue