]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Add impl property to PostgreSQL / Oracle INTERVAL class
authorMajorDallas <79329882+MajorDallas@users.noreply.github.com>
Tue, 22 Jun 2021 19:34:09 +0000 (15:34 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Tue, 22 Jun 2021 22:01:33 +0000 (18:01 -0400)
Fixed issue where the ``INTERVAL`` datatype on PostgreSQL and Oracle would
produce an ``AttributeError`` when used in the context of a comparison
operation against a ``timedelta()`` object. Pull request courtesy
MajorDallas.

Fixes: #6649
Closes: #6650
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/6650
Pull-request-sha: dd217a975e5f0d3157e81c731791225b6a32889f

Change-Id: I773caf2673294fdb3c92b42895ad714e944d1bf8

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

diff --git a/doc/build/changelog/unreleased_14/6649.rst b/doc/build/changelog/unreleased_14/6649.rst
new file mode 100644 (file)
index 0000000..70ec642
--- /dev/null
@@ -0,0 +1,8 @@
+.. change::
+    :tags: bug, postgresql, oracle
+    :tickets: 6649
+
+    Fixed issue where the ``INTERVAL`` datatype on PostgreSQL and Oracle would
+    produce an ``AttributeError`` when used in the context of a comparison
+    operation against a ``timedelta()`` object. Pull request courtesy
+    MajorDallas.
index 57f55c1824bc69eb017aac742c5e6d64340bc02c..a72088a461b8cfb4f7932f93bcac2be4f33947cd 100644 (file)
@@ -702,6 +702,9 @@ class INTERVAL(sqltypes.NativeForEmulated, sqltypes._AbstractInterval):
             day_precision=self.day_precision,
         )
 
+    def coerce_compared_value(self, op, value):
+        return self
+
 
 class ROWID(sqltypes.TypeEngine):
     """Oracle ROWID type.
index deb6243296212948d6eb4328b4cd423e8ff39bd7..4c789813290eafd8fb060d1e3af9ba865c243637 100644 (file)
@@ -1655,6 +1655,9 @@ class INTERVAL(sqltypes.NativeForEmulated, sqltypes._AbstractInterval):
     def python_type(self):
         return dt.timedelta
 
+    def coerce_compared_value(self, op, value):
+        return self
+
 
 PGInterval = INTERVAL
 
index 4b119602574e51b59b1e40faad6bcadff08b8382..70b00c06f206fdaf70fe24f4ee6d90f4da054f24 100644 (file)
@@ -183,6 +183,10 @@ class DialectTypesTest(fixtures.TestBase, AssertsCompiledSQL):
     def test_interval(self, type_, expected):
         self.assert_compile(type_, expected)
 
+    def test_interval_coercion_literal(self):
+        expr = column("bar", oracle.INTERVAL) == datetime.timedelta(days=1)
+        eq_(expr.right.type._type_affinity, sqltypes.Interval)
+
 
 class TypesTest(fixtures.TestBase):
     __only_on__ = "oracle"
index c83fe0f8a114b19ed18b92bc9eda4dc11fd6df96..3fdb31b7cb5793967d65904bc1dcf5d2940379b6 100644 (file)
@@ -2427,6 +2427,10 @@ class TimestampTest(fixtures.TestBase, AssertsExecutionResults):
         eq_(expr.type._type_affinity, types.Interval)
         assert isinstance(expr.type, postgresql.INTERVAL)
 
+    def test_interval_coercion_literal(self):
+        expr = column("bar", postgresql.INTERVAL) == datetime.timedelta(days=1)
+        eq_(expr.right.type._type_affinity, types.Interval)
+
 
 class SpecialTypesCompileTest(fixtures.TestBase, AssertsCompiledSQL):
     __dialect__ = "postgresql"