From 78eecd55fd9fad07030d963f5fd6713c4af60e80 Mon Sep 17 00:00:00 2001 From: Gilbert Gilb's Date: Sat, 22 Jan 2022 03:30:55 +0100 Subject: [PATCH] Remove postgres version check for NOT VALID constraints. - 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 | 13 ++----------- test/dialect/postgresql/test_compiler.py | 20 -------------------- 2 files changed, 2 insertions(+), 31 deletions(-) diff --git a/lib/sqlalchemy/dialects/postgresql/base.py b/lib/sqlalchemy/dialects/postgresql/base.py index 5f905d617a..e41f8dfc2a 100644 --- a/lib/sqlalchemy/dialects/postgresql/base.py +++ b/lib/sqlalchemy/dialects/postgresql/base.py @@ -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 diff --git a/test/dialect/postgresql/test_compiler.py b/test/dialect/postgresql/test_compiler.py index ae4d73c7aa..53ac1cb46c 100644 --- a/test/dialect/postgresql/test_compiler.py +++ b/test/dialect/postgresql/test_compiler.py @@ -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)) -- 2.47.3