]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Derive `next_value.type` from `Sequence.data_type` if available
authorBryan Forbes <bryan@reigndropsfall.net>
Thu, 15 Apr 2021 17:35:52 +0000 (12:35 -0500)
committerBryan Forbes <bryan@reigndropsfall.net>
Sun, 18 Apr 2021 18:54:57 +0000 (13:54 -0500)
Fixes #6287

Change-Id: I7d428ed86cd72cd910bfff9058a52c7fcb7c64ac

doc/build/changelog/unreleased_14/6287.rst [new file with mode: 0644]
lib/sqlalchemy/sql/functions.py
test/sql/test_sequences.py

diff --git a/doc/build/changelog/unreleased_14/6287.rst b/doc/build/changelog/unreleased_14/6287.rst
new file mode 100644 (file)
index 0000000..6dfc183
--- /dev/null
@@ -0,0 +1,7 @@
+.. change::
+    :tags: bug
+    :tickets: 6287
+    :versions: 1.4.9
+
+    Fixed a bug where ``sqlalchemy.sql.functions.next_value`` was not deriving
+    its ``type`` from the ``Sequence`` that created it.
index d71926a1f9797023950510da9d443a935b9ab831..02ed55100158864a473e8d9500046db6530e928c 100644 (file)
@@ -1064,6 +1064,9 @@ class next_value(GenericFunction):
         ), "next_value() accepts a Sequence object as input."
         self._bind = self._get_bind(kw)
         self.sequence = seq
+        self.type = sqltypes.to_instance(
+            seq.data_type or getattr(self, "type", None)
+        )
 
     def compare(self, other, **kw):
         return (
index dd8491d310cec4d6eb0f255db3709f6a7385392e..3b25ba2ad0d8da02bfde1d863adb1e25361e30e3 100644 (file)
@@ -1,4 +1,5 @@
 import sqlalchemy as sa
+from sqlalchemy import BigInteger
 from sqlalchemy import Integer
 from sqlalchemy import MetaData
 from sqlalchemy import Sequence
@@ -387,6 +388,10 @@ class SequenceTest(fixtures.TestBase, testing.AssertsCompiledSQL):
         is_false(testing.db.dialect.has_table(connection, "table_1"))
         is_false(testing.db.dialect.has_table(connection, "table_2"))
 
+    def test_next_value_type(self):
+        seq = Sequence("my_sequence", data_type=BigInteger)
+        assert isinstance(seq.next_value().type, BigInteger)
+
 
 class FutureSequenceTest(fixtures.FutureEngineMixin, SequenceTest):
     __requires__ = ("sequences",)