]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Fix identity column reflection failure
authorGord Thompson <gord@gordthompson.com>
Fri, 20 Oct 2023 14:19:42 +0000 (08:19 -0600)
committerGord Thompson <gord@gordthompson.com>
Fri, 20 Oct 2023 19:52:42 +0000 (13:52 -0600)
Fixes: #10504
Fix reflection failure for bigint identity column with
a large identity start value (more than 18 digits).

Change-Id: I8a7ec114e4596b1710d789a4a4fb08013edd80ce
(cherry picked from commit 4c46ed6a9f6f93abd5abe5ba4b95c4c1e8f52a4c)

doc/build/changelog/unreleased_14/10504.rst [new file with mode: 0644]
lib/sqlalchemy/dialects/mssql/information_schema.py
test/dialect/mssql/test_reflection.py

diff --git a/doc/build/changelog/unreleased_14/10504.rst b/doc/build/changelog/unreleased_14/10504.rst
new file mode 100644 (file)
index 0000000..7afc00f
--- /dev/null
@@ -0,0 +1,8 @@
+.. change::
+    :tags: bug, mssql, reflection
+    :tickets: 10504
+    :versions: 2.0.23
+
+    Fixed issue where identity column reflection would fail
+    for a bigint column with a large identity start value
+    (more than 18 digits).
index 8ca95d79b5b621c8aefae44ddd92bd46a698b9d3..998757c1708098fa196c8d05beb6256924dad7e4 100644 (file)
@@ -215,7 +215,7 @@ class IdentitySqlVariant(TypeDecorator):
     cache_ok = True
 
     def column_expression(self, colexpr):
-        return cast(colexpr, Numeric)
+        return cast(colexpr, Numeric(38, 0))
 
 
 identity_columns = Table(
index d24ee4adb9a3f12567e57cfba1223fb49a382348..125959cf9d817dbc6d1d637aa5336762dc93661a 100644 (file)
@@ -847,7 +847,11 @@ class IdentityReflectionTest(fixtures.TablesTest):
                     ),
                 ),
                 Column("id2", Integer, Identity()),
-                Column("id3", sqltypes.BigInteger, Identity()),
+                Column(
+                    "id3",
+                    sqltypes.BigInteger,
+                    Identity(start=-9223372036854775808),
+                ),
                 Column("id4", sqltypes.SmallInteger, Identity()),
                 Column("id5", sqltypes.Numeric, Identity()),
             ]
@@ -869,7 +873,10 @@ class IdentityReflectionTest(fixtures.TablesTest):
                 eq_(type(col["identity"]["start"]), int)
                 eq_(type(col["identity"]["increment"]), int)
             elif col["name"] == "id3":
-                eq_(col["identity"], {"start": 1, "increment": 1})
+                eq_(
+                    col["identity"],
+                    {"start": -9223372036854775808, "increment": 1},
+                )
                 eq_(type(col["identity"]["start"]), util.compat.long_type)
                 eq_(type(col["identity"]["increment"]), util.compat.long_type)
             elif col["name"] == "id4":