Commit 87a8046f authored by Ian Kelly's avatar Ian Kelly
Browse files

Made the oracle backend throw the same ValueError as the mysql backend when a...

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
parent e0e347c2
Loading
Loading
Loading
Loading
+13 −0
Original line number Diff line number Diff line
@@ -292,11 +292,24 @@ WHEN (new.%(col_name)s IS NULL)
        return "%sTABLESPACE %s" % ((inline and "USING INDEX " or ""),
            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):
        if value is None:
            return None

        if isinstance(value, basestring):
            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,
                                 value.second, value.microsecond)

+2 −2
Original line number Diff line number Diff line
@@ -76,8 +76,8 @@ class DataTypesTestCase(TestCase):

    @skipIfDBFeature('supports_timezones')
    def test_error_on_timezone(self):
        """Regression test for #8354: the MySQL backend should raise an error
        if given a timezone-aware datetime object."""
        """Regression test for #8354: the MySQL and Oracle backends should raise
        an error if given a timezone-aware datetime object."""
        dt = datetime.datetime(2008, 8, 31, 16, 20, tzinfo=tzinfo.FixedOffset(0))
        d = Donut(name='Bear claw', consumed_at=dt)
        self.assertRaises(ValueError, d.save)