summaryrefslogtreecommitdiff
path: root/test/dialect/postgresql/test_reflection.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2021-03-30 14:48:41 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2021-03-30 14:49:46 -0400
commitab61d66dee9b3c3639907557852908858daacb6f (patch)
tree1c884eb2d0372372bc9146f42bedddb4cacdccde /test/dialect/postgresql/test_reflection.py
parent57aac308cea2bdb5b1a15f05bf8ad479f66611d9 (diff)
downloadsqlalchemy-ab61d66dee9b3c3639907557852908858daacb6f.tar.gz
Refine domain nullable rules for PostgreSQL reflection
Fixed issue in PostgreSQL reflection where a column expressing "NOT NULL" will supersede the nullability of a corresponding domain. Fixes #6161 Change-Id: I1a3de49afcdb952f71bd7a7cc7b264513c93eff5
Diffstat (limited to 'test/dialect/postgresql/test_reflection.py')
-rw-r--r--test/dialect/postgresql/test_reflection.py21
1 files changed, 21 insertions, 0 deletions
diff --git a/test/dialect/postgresql/test_reflection.py b/test/dialect/postgresql/test_reflection.py
index 855464916..a7876a766 100644
--- a/test/dialect/postgresql/test_reflection.py
+++ b/test/dialect/postgresql/test_reflection.py
@@ -36,6 +36,7 @@ from sqlalchemy.testing import mock
from sqlalchemy.testing.assertions import assert_raises
from sqlalchemy.testing.assertions import AssertsExecutionResults
from sqlalchemy.testing.assertions import eq_
+from sqlalchemy.testing.assertions import is_
from sqlalchemy.testing.assertions import is_true
@@ -297,6 +298,9 @@ class DomainReflectionTest(fixtures.TestBase, AssertsExecutionResults):
"CREATE DOMAIN enumdomain AS testtype",
"CREATE DOMAIN arraydomain AS INTEGER[]",
'CREATE DOMAIN "SomeSchema"."Quoted.Domain" INTEGER DEFAULT 0',
+ "CREATE DOMAIN nullable_domain AS TEXT CHECK "
+ "(VALUE IN('FOO', 'BAR'))",
+ "CREATE DOMAIN not_nullable_domain AS TEXT NOT NULL",
]:
try:
con.exec_driver_sql(ddl)
@@ -329,6 +333,11 @@ class DomainReflectionTest(fixtures.TestBase, AssertsExecutionResults):
"CREATE TABLE quote_test "
'(id integer, data "SomeSchema"."Quoted.Domain")'
)
+ con.exec_driver_sql(
+ "CREATE TABLE nullable_domain_test "
+ "(not_nullable_domain_col nullable_domain not null,"
+ "nullable_local not_nullable_domain)"
+ )
@classmethod
def teardown_test_class(cls):
@@ -347,6 +356,10 @@ class DomainReflectionTest(fixtures.TestBase, AssertsExecutionResults):
con.exec_driver_sql('DROP DOMAIN "SomeSchema"."Quoted.Domain"')
con.exec_driver_sql('DROP SCHEMA "SomeSchema"')
+ con.exec_driver_sql("DROP TABLE nullable_domain_test")
+ con.exec_driver_sql("DROP DOMAIN nullable_domain")
+ con.exec_driver_sql("DROP DOMAIN not_nullable_domain")
+
def test_table_is_reflected(self, connection):
metadata = MetaData()
table = Table("testtable", metadata, autoload_with=connection)
@@ -357,6 +370,14 @@ class DomainReflectionTest(fixtures.TestBase, AssertsExecutionResults):
)
assert isinstance(table.c.answer.type, Integer)
+ def test_nullable_from_domain(self, connection):
+ metadata = MetaData()
+ table = Table(
+ "nullable_domain_test", metadata, autoload_with=connection
+ )
+ is_(table.c.not_nullable_domain_col.nullable, False)
+ is_(table.c.nullable_local.nullable, False)
+
def test_domain_is_reflected(self, connection):
metadata = MetaData()
table = Table("testtable", metadata, autoload_with=connection)