diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2019-06-26 11:45:50 -0400 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2019-06-26 15:10:53 -0400 |
| commit | 5cf8e14d58c89fdb94c60bf5e94d8b13d296da25 (patch) | |
| tree | 9819e92b6dcce02ad453bac70841446843e0c05e /lib/sqlalchemy/testing/suite/test_reflection.py | |
| parent | 1ed2f1621510b48a6c46bedf3dd579c56bd89ccb (diff) | |
| download | sqlalchemy-5cf8e14d58c89fdb94c60bf5e94d8b13d296da25.tar.gz | |
Reflect "NO ACTION" as None; support "RESTRICT"
The "NO ACTION" keyword for foreign key "ON UPDATE" is now considered to be
the default cascade for a foreign key on all supporting backends (SQlite,
MySQL, PostgreSQL) and when detected is not included in the reflection
dictionary; this is already the behavior for PostgreSQL and MySQL for all
previous SQLAlchemy versions in any case. The "RESTRICT" keyword is
positively stored when detected; PostgreSQL does report on this keyword,
and MySQL as of version 8.0 does as well. On earlier MySQL versions, it is
not reported by the database.
Fixes: #4741
Change-Id: I6becf1f2450605c1991158bb8a04d954dcc7396c
Diffstat (limited to 'lib/sqlalchemy/testing/suite/test_reflection.py')
| -rw-r--r-- | lib/sqlalchemy/testing/suite/test_reflection.py | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/lib/sqlalchemy/testing/suite/test_reflection.py b/lib/sqlalchemy/testing/suite/test_reflection.py index e529a0753..53e1599b3 100644 --- a/lib/sqlalchemy/testing/suite/test_reflection.py +++ b/lib/sqlalchemy/testing/suite/test_reflection.py @@ -671,10 +671,29 @@ class ComponentReflectionTest(fixtures.TablesTest): def test_get_foreign_key_options_onupdate(self): self._test_get_foreign_key_options(onupdate="SET NULL") + @testing.requires.foreign_key_constraint_option_reflection_onupdate + def test_get_foreign_key_options_onupdate_noaction(self): + self._test_get_foreign_key_options(onupdate="NO ACTION", expected={}) + + @testing.requires.fk_constraint_option_reflection_ondelete_noaction + def test_get_foreign_key_options_ondelete_noaction(self): + self._test_get_foreign_key_options(ondelete="NO ACTION", expected={}) + + @testing.requires.fk_constraint_option_reflection_onupdate_restrict + def test_get_foreign_key_options_onupdate_restrict(self): + self._test_get_foreign_key_options(onupdate="RESTRICT") + + @testing.requires.fk_constraint_option_reflection_ondelete_restrict + def test_get_foreign_key_options_ondelete_restrict(self): + self._test_get_foreign_key_options(ondelete="RESTRICT") + @testing.provide_metadata - def _test_get_foreign_key_options(self, **options): + def _test_get_foreign_key_options(self, expected=None, **options): meta = self.metadata + if expected is None: + expected = options + Table( "x", meta, @@ -714,7 +733,8 @@ class ComponentReflectionTest(fixtures.TablesTest): eq_(dict((k, opts[k]) for k in opts if opts[k]), {}) opts = insp.get_foreign_keys("user")[0]["options"] - eq_(dict((k, opts[k]) for k in opts if opts[k]), options) + eq_(opts, expected) + # eq_(dict((k, opts[k]) for k in opts if opts[k]), expected) def _assert_insp_indexes(self, indexes, expected_indexes): index_names = [d["name"] for d in indexes] |
