]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Remove postgres version check for NOT VALID constraints. 7601/head
authorGilbert Gilb's <gilbsgilbert@gmail.com>
Sat, 22 Jan 2022 02:30:55 +0000 (03:30 +0100)
committerGilbert Gilb's <gilbsgilbert@gmail.com>
Sun, 23 Jan 2022 17:53:54 +0000 (18:53 +0100)
- PostgreSQL 9.0 has reached EOL more than 6 years ago
- SQLAlchemy "normal support" is based at 9.6: https://docs.sqlalchemy.org/en/14/dialects/postgresql.html
- One can still not use the option and it will still work with older
  postgres version

lib/sqlalchemy/dialects/postgresql/base.py
test/dialect/postgresql/test_compiler.py

index 5f905d617aa5e7cfbd7ca73061e9d9a10dc43133..e41f8dfc2a7d9a5973db53e46cdb2ec292eba825 100644 (file)
@@ -2599,12 +2599,8 @@ class PGDDLCompiler(compiler.DDLCompiler):
         return colspec
 
     def _define_constraint_validity(self, constraint):
-        if self.dialect._supports_not_valid_constraints:
-            not_valid = constraint.dialect_options["postgresql"]["not_valid"]
-            if not_valid:
-                return " NOT VALID"
-
-        return ""
+        not_valid = constraint.dialect_options["postgresql"]["not_valid"]
+        return " NOT VALID" if not_valid else ""
 
     def visit_check_constraint(self, constraint):
         if constraint._type_bound:
@@ -3264,7 +3260,6 @@ class PGDialect(default.DefaultDialect):
     _backslash_escapes = True
     _supports_create_index_concurrently = True
     _supports_drop_index_concurrently = True
-    _supports_not_valid_constraints = True
 
     def __init__(self, json_serializer=None, json_deserializer=None, **kwargs):
         default.DefaultDialect.__init__(self, **kwargs)
@@ -3307,10 +3302,6 @@ class PGDialect(default.DefaultDialect):
             2,
         )
         self.supports_identity_columns = self.server_version_info >= (10,)
-        self._supports_not_valid_constraints = self.server_version_info >= (
-            9,
-            1,
-        )
 
     def get_isolation_level_values(self, dbapi_conn):
         # note the generic dialect doesn't have AUTOCOMMIT, however
index ae4d73c7aa088f57a9ab412eabb67b511e809883..53ac1cb46c5fac89ac7742910b57ccdee41752ae 100644 (file)
@@ -845,14 +845,6 @@ class CompileTest(fixtures.TestBase, AssertsCompiledSQL):
             "CREATE TABLE testtbl (data INTEGER, CHECK (data = 0) NOT VALID)",
         )
 
-        dialect_9_0 = postgresql.dialect()
-        dialect_9_0._supports_not_valid_constraints = False
-        self.assert_compile(
-            schema.CreateTable(tbl),
-            "CREATE TABLE testtbl (data INTEGER, CHECK (data = 0))",
-            dialect=dialect_9_0,
-        )
-
     def test_create_foreign_key_constraint_not_valid(self):
         m = MetaData()
 
@@ -875,18 +867,6 @@ class CompileTest(fixtures.TestBase, AssertsCompiledSQL):
             ")",
         )
 
-        dialect_9_0 = postgresql.dialect()
-        dialect_9_0._supports_not_valid_constraints = False
-        self.assert_compile(
-            schema.CreateTable(tbl),
-            "CREATE TABLE testtbl ("
-            "a INTEGER, "
-            "b INTEGER, "
-            "FOREIGN KEY(b) REFERENCES testtbl (a)"
-            ")",
-            dialect=dialect_9_0,
-        )
-
     def test_exclude_constraint_min(self):
         m = MetaData()
         tbl = Table("testtbl", m, Column("room", Integer, primary_key=True))