summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--doc/build/changelog/unreleased_14/6287.rst7
-rw-r--r--lib/sqlalchemy/sql/functions.py3
-rw-r--r--test/sql/test_sequences.py5
3 files changed, 15 insertions, 0 deletions
diff --git a/doc/build/changelog/unreleased_14/6287.rst b/doc/build/changelog/unreleased_14/6287.rst
new file mode 100644
index 000000000..6dfc18319
--- /dev/null
+++ b/doc/build/changelog/unreleased_14/6287.rst
@@ -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.
diff --git a/lib/sqlalchemy/sql/functions.py b/lib/sqlalchemy/sql/functions.py
index d71926a1f..02ed55100 100644
--- a/lib/sqlalchemy/sql/functions.py
+++ b/lib/sqlalchemy/sql/functions.py
@@ -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 (
diff --git a/test/sql/test_sequences.py b/test/sql/test_sequences.py
index dd8491d31..3b25ba2ad 100644
--- a/test/sql/test_sequences.py
+++ b/test/sql/test_sequences.py
@@ -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",)