From: Bryan Forbes Date: Thu, 15 Apr 2021 17:35:52 +0000 (-0500) Subject: Derive `next_value.type` from `Sequence.data_type` if available X-Git-Tag: rel_1_4_10~6^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=adc950945025d436ef97095b4e706700ebae34ff;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git Derive `next_value.type` from `Sequence.data_type` if available Fixes #6287 Change-Id: I7d428ed86cd72cd910bfff9058a52c7fcb7c64ac --- diff --git a/doc/build/changelog/unreleased_14/6287.rst b/doc/build/changelog/unreleased_14/6287.rst new file mode 100644 index 0000000000..6dfc18319a --- /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 d71926a1f9..02ed551001 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 dd8491d310..3b25ba2ad0 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",)