]> 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:30:47 +0000 (13:30 -0600)
Fixes: #10504
Fix reflection failure for bigint identity column with
a large identity start value (more than 18 digits).

Change-Id: I8a7ec114e4596b1710d789a4a4fb08013edd80ce

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 5bf81e867625188dc43e8e325754fd8038ffabdc..e770313f9379e93faf1cdcc0ae48a6e2e1cebf0d 100644 (file)
@@ -211,7 +211,7 @@ class NumericSqlVariant(TypeDecorator):
     cache_ok = True
 
     def column_expression(self, colexpr):
-        return cast(colexpr, Numeric)
+        return cast(colexpr, Numeric(38, 0))
 
 
 identity_columns = Table(
index 122c5d7e3250d906bb04454528d66c230f5844d1..b6a1d411a254a607dc7d56f4362177fe556dcfb2 100644 (file)
@@ -1196,7 +1196,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()),
             ]
@@ -1218,7 +1222,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"]), int)
                 eq_(type(col["identity"]["increment"]), int)
             elif col["name"] == "id4":