]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Repair Oracle Interval
authorMike Bayer <mike_mp@zzzcomputing.com>
Mon, 11 Nov 2019 21:51:46 +0000 (16:51 -0500)
committerMike Bayer <mike_mp@zzzcomputing.com>
Mon, 11 Nov 2019 21:51:46 +0000 (16:51 -0500)
The :class:`.oracle.INTERVAL` class of the Oracle dialect is now correctly
a subclass of the abstract version of :class:`.Interval` as well as the
correct "emulated" base class, which allows for correct behavior under both
native and non-native modes; previously it was only based on
:class:`.TypeEngine`.

Fixes: #4971
Change-Id: I4400d9f090330388460cca930e4139e3bd21eb11

doc/build/changelog/unreleased_14/4971.rst [new file with mode: 0644]
lib/sqlalchemy/dialects/oracle/base.py
test/sql/test_types.py

diff --git a/doc/build/changelog/unreleased_14/4971.rst b/doc/build/changelog/unreleased_14/4971.rst
new file mode 100644 (file)
index 0000000..08e94a0
--- /dev/null
@@ -0,0 +1,10 @@
+.. change::
+    :tags: bug, oracle
+    :tickets: 4971
+
+    The :class:`.oracle.INTERVAL` class of the Oracle dialect is now correctly
+    a subclass of the abstract version of :class:`.Interval` as well as the
+    correct "emulated" base class, which allows for correct behavior under both
+    native and non-native modes; previously it was only based on
+    :class:`.TypeEngine`.
+
index c1e91fb122772611bea394c998e64bde43b85fff..fe3d586a48e2c3b7ebe5459689aafa8310043b15 100644 (file)
@@ -450,12 +450,12 @@ from ... import Computed
 from ... import exc
 from ... import schema as sa_schema
 from ... import sql
-from ... import types as sqltypes
 from ... import util
 from ...engine import default
 from ...engine import reflection
 from ...sql import compiler
 from ...sql import expression
+from ...sql import sqltypes
 from ...sql import util as sql_util
 from ...sql import visitors
 from ...types import BLOB
@@ -567,7 +567,7 @@ class DATE(sqltypes.DateTime):
         return other._type_affinity in (sqltypes.DateTime, sqltypes.Date)
 
 
-class INTERVAL(sqltypes.TypeEngine):
+class INTERVAL(sqltypes.NativeForEmulated, sqltypes._AbstractInterval):
     __visit_name__ = "INTERVAL"
 
     def __init__(self, day_precision=None, second_precision=None):
index 6359728eb1f11c1fe7367ed24b549342e3b9690b..d40d0902f35d6ff048599d604a9772965f00ee88 100644 (file)
@@ -2857,7 +2857,6 @@ class IntervalTest(fixtures.TestBase, AssertsExecutionResults):
     def teardown_class(cls):
         metadata.drop_all()
 
-    @testing.fails_on("oracle", "See issue #4971")
     def test_non_native_adapt(self):
         interval = Interval(native=False)
         adapted = interval.dialect_impl(testing.db.dialect)
@@ -2865,31 +2864,30 @@ class IntervalTest(fixtures.TestBase, AssertsExecutionResults):
         assert adapted.native is False
         eq_(str(adapted), "DATETIME")
 
-    @testing.fails_on(
-        "oracle",
-        "ORA-01873: the leading precision of the interval is too small",
-    )
     def test_roundtrip(self):
         small_delta = datetime.timedelta(days=15, seconds=5874)
-        delta = datetime.timedelta(414)
-        interval_table.insert().execute(
-            native_interval=small_delta,
-            native_interval_args=delta,
-            non_native_interval=delta,
-        )
-        row = interval_table.select().execute().first()
+        delta = datetime.timedelta(14)
+        with testing.db.begin() as conn:
+            conn.execute(
+                interval_table.insert(),
+                native_interval=small_delta,
+                native_interval_args=delta,
+                non_native_interval=delta,
+            )
+            row = conn.execute(interval_table.select()).first()
         eq_(row["native_interval"], small_delta)
         eq_(row["native_interval_args"], delta)
         eq_(row["non_native_interval"], delta)
 
-    @testing.fails_on(
-        "oracle", "ORA-00932: inconsistent datatypes: expected NUMBER got DATE"
-    )
     def test_null(self):
-        interval_table.insert().execute(
-            id=1, native_inverval=None, non_native_interval=None
-        )
-        row = interval_table.select().execute().first()
+        with testing.db.begin() as conn:
+            conn.execute(
+                interval_table.insert(),
+                id=1,
+                native_inverval=None,
+                non_native_interval=None,
+            )
+            row = conn.execute(interval_table.select()).first()
         eq_(row["native_interval"], None)
         eq_(row["native_interval_args"], None)
         eq_(row["non_native_interval"], None)