diff options
author | Bill Finn <bill@angaza.com> | 2019-08-27 12:21:57 -0400 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2019-08-27 12:54:04 -0400 |
commit | 3980a9a455d08c5073cabc3c2b77de46fa36d7b4 (patch) | |
tree | 7c4c4634dfaf9bf1de13f7315bd8424cc1b356fa /test/dialect/postgresql/test_reflection.py | |
parent | 5bf264ca08b8bb38d50baeb48fe1729da4164711 (diff) | |
download | sqlalchemy-3980a9a455d08c5073cabc3c2b77de46fa36d7b4.tar.gz |
PGDialect.get_check_constraints: Handle "NOT VALID"
Added support for reflection of CHECK constraints that include the special
PostgreSQL qualifier "NOT VALID", which can be present for CHECK
constraints that were added to an exsiting table with the directive that
they not be applied to existing data in the table. The PostgreSQL
dictionary for CHECK constraints as returned by
:meth:`.Inspector.get_check_constraints` may include an additional entry
``dialect_options`` which within will contain an entry ``"not_valid":
True`` if this symbol is detected. Pull request courtesy Bill Finn.
Fixes: #4824
Closes: #4825
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/4825
Pull-request-sha: a0e1ab133c2d46521a74e55423ac2ba866682dae
Change-Id: I78365f50055c95474c92124b85df66c5c80c00c8
Diffstat (limited to 'test/dialect/postgresql/test_reflection.py')
-rw-r--r-- | test/dialect/postgresql/test_reflection.py | 29 |
1 files changed, 27 insertions, 2 deletions
diff --git a/test/dialect/postgresql/test_reflection.py b/test/dialect/postgresql/test_reflection.py index 4b5c4b949..7054a9fdd 100644 --- a/test/dialect/postgresql/test_reflection.py +++ b/test/dialect/postgresql/test_reflection.py @@ -1540,9 +1540,10 @@ class ReflectionTest(fixtures.TestBase): ) def test_reflect_check_warning(self): + rows = [("some name", "NOTCHECK foobar")] conn = mock.Mock( - execute=lambda *arg, **kw: mock.Mock( - fetchall=lambda: [("some name", "NOTCHECK foobar")] + execute=lambda *arg, **kw: mock.MagicMock( + fetchall=lambda: rows, __iter__=lambda self: iter(rows) ) ) with mock.patch.object( @@ -1553,6 +1554,30 @@ class ReflectionTest(fixtures.TestBase): ): testing.db.dialect.get_check_constraints(conn, "foo") + def test_reflect_with_not_valid_check_constraint(self): + rows = [("some name", "CHECK ((a IS NOT NULL)) NOT VALID")] + conn = mock.Mock( + execute=lambda *arg, **kw: mock.MagicMock( + fetchall=lambda: rows, __iter__=lambda self: iter(rows) + ) + ) + with mock.patch.object( + testing.db.dialect, "get_table_oid", lambda *arg, **kw: 1 + ): + check_constraints = testing.db.dialect.get_check_constraints( + conn, "foo" + ) + eq_( + check_constraints, + [ + { + "name": "some name", + "sqltext": "a IS NOT NULL", + "dialect_options": {"not_valid": True}, + } + ], + ) + class CustomTypeReflectionTest(fixtures.TestBase): class CustomType(object): |