From 87a8046f9030646adec583c34597a1f634a0d11b Mon Sep 17 00:00:00 2001 From: Ian Kelly Date: Fri, 12 Nov 2010 18:39:30 +0000 Subject: [PATCH] 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 --- django/db/backends/oracle/base.py | 13 +++++++++++++ tests/regressiontests/datatypes/tests.py | 4 ++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/django/db/backends/oracle/base.py b/django/db/backends/oracle/base.py index d3faa96e65..3e8eae4d3f 100644 --- a/django/db/backends/oracle/base.py +++ b/django/db/backends/oracle/base.py @@ -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) diff --git a/tests/regressiontests/datatypes/tests.py b/tests/regressiontests/datatypes/tests.py index 1d44552a37..eb09a5a637 100644 --- a/tests/regressiontests/datatypes/tests.py +++ b/tests/regressiontests/datatypes/tests.py @@ -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)