Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Made the oracle backend throw the same ValueError as the mysql backen…

…d 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
  • Loading branch information...
commit 87a8046f9030646adec583c34597a1f634a0d11b 1 parent e0e347c
Ian Kelly authored November 12, 2010
13  django/db/backends/oracle/base.py
@@ -292,11 +292,24 @@ def tablespace_sql(self, tablespace, inline=False):
292 292
         return "%sTABLESPACE %s" % ((inline and "USING INDEX " or ""),
293 293
             self.quote_name(tablespace))
294 294
 
  295
+    def value_to_db_datetime(self, value):
  296
+        # Oracle doesn't support tz-aware datetimes
  297
+        if getattr(value, 'tzinfo', None) is not None:
  298
+            raise ValueError("Oracle backend does not support timezone-aware datetimes.")
  299
+
  300
+        return super(DatabaseOperations, self).value_to_db_datetime(value)
  301
+
295 302
     def value_to_db_time(self, value):
296 303
         if value is None:
297 304
             return None
  305
+
298 306
         if isinstance(value, basestring):
299 307
             return datetime.datetime(*(time.strptime(value, '%H:%M:%S')[:6]))
  308
+
  309
+        # Oracle doesn't support tz-aware datetimes
  310
+        if value.tzinfo is not None:
  311
+            raise ValueError("Oracle backend does not support timezone-aware datetimes.")
  312
+
300 313
         return datetime.datetime(1900, 1, 1, value.hour, value.minute,
301 314
                                  value.second, value.microsecond)
302 315
 
4  tests/regressiontests/datatypes/tests.py
@@ -76,8 +76,8 @@ def test_textfields_unicode(self):
76 76
 
77 77
     @skipIfDBFeature('supports_timezones')
78 78
     def test_error_on_timezone(self):
79  
-        """Regression test for #8354: the MySQL backend should raise an error
80  
-        if given a timezone-aware datetime object."""
  79
+        """Regression test for #8354: the MySQL and Oracle backends should raise
  80
+        an error if given a timezone-aware datetime object."""
81 81
         dt = datetime.datetime(2008, 8, 31, 16, 20, tzinfo=tzinfo.FixedOffset(0))
82 82
         d = Donut(name='Bear claw', consumed_at=dt)
83 83
         self.assertRaises(ValueError, d.save)

0 notes on commit 87a8046

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