diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2020-12-29 21:06:15 -0500 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2020-12-29 21:11:15 -0500 |
| commit | 8e159832596f15865f89675fa19202b171c99d7a (patch) | |
| tree | b852d8f453fe808074b1cff68a1aed8159359e22 /lib/sqlalchemy/testing | |
| parent | 97657da543985f2c1369a64202eff559d7bf6d00 (diff) | |
| download | sqlalchemy-8e159832596f15865f89675fa19202b171c99d7a.tar.gz | |
disambiguate SQL server temp table constraint names
This seems to be raising errors lately which was not the
case earlier, however SQL Server seems to produce name conflicts
for named constraints against temp tables in different databases.
I can raise the error every time here running two tests
from ComponentReflectionTest with -n2. Unknown why the issue
is happening now and didn't occur for several months.
https://www.arbinada.com/en/node/1645 has some background.
Change-Id: I8854dfd88503fb855a7e12622ebe97c08915e5bb
Diffstat (limited to 'lib/sqlalchemy/testing')
| -rw-r--r-- | lib/sqlalchemy/testing/config.py | 1 | ||||
| -rw-r--r-- | lib/sqlalchemy/testing/provision.py | 5 | ||||
| -rw-r--r-- | lib/sqlalchemy/testing/suite/test_reflection.py | 18 |
3 files changed, 22 insertions, 2 deletions
diff --git a/lib/sqlalchemy/testing/config.py b/lib/sqlalchemy/testing/config.py index 8c232f319..0b8027b84 100644 --- a/lib/sqlalchemy/testing/config.py +++ b/lib/sqlalchemy/testing/config.py @@ -15,6 +15,7 @@ file_config = None test_schema = None test_schema_2 = None _current = None +ident = "main" _fixture_functions = None # installed by plugin_base diff --git a/lib/sqlalchemy/testing/provision.py b/lib/sqlalchemy/testing/provision.py index aa14a9c1a..c4f489a69 100644 --- a/lib/sqlalchemy/testing/provision.py +++ b/lib/sqlalchemy/testing/provision.py @@ -67,6 +67,11 @@ def setup_config(db_url, options, file_config, follower_ident): eng.connect().close() cfg = config.Config.register(eng, db_opts, options, file_config) + + # a symbolic name that tests can use if they need to disambiguate + # names across databases + config.ident = follower_ident + if follower_ident: configure_follower(cfg, follower_ident) return cfg diff --git a/lib/sqlalchemy/testing/suite/test_reflection.py b/lib/sqlalchemy/testing/suite/test_reflection.py index 3e4d7a2c0..f1c573662 100644 --- a/lib/sqlalchemy/testing/suite/test_reflection.py +++ b/lib/sqlalchemy/testing/suite/test_reflection.py @@ -458,7 +458,13 @@ class ComponentReflectionTest(fixtures.TablesTest): Column("id", sa.INT, primary_key=True), Column("name", sa.VARCHAR(50)), Column("foo", sa.INT), - sa.UniqueConstraint("name", name="user_tmp_uq"), + # disambiguate temp table unique constraint names. this is + # pretty arbitrary for a generic dialect however we are doing + # it to suit SQL Server which will produce name conflicts for + # unique constraints created against temp tables in different + # databases. + # https://www.arbinada.com/en/node/1645 + sa.UniqueConstraint("name", name="user_tmp_uq_%s" % config.ident), sa.Index("user_tmp_ix", "foo"), **kw ) @@ -1091,7 +1097,15 @@ class ComponentReflectionTest(fixtures.TablesTest): # Different dialects handle duplicate index and constraints # differently, so ignore this flag refl.pop("duplicates_index", None) - eq_(reflected, [{"column_names": ["name"], "name": "user_tmp_uq"}]) + eq_( + reflected, + [ + { + "column_names": ["name"], + "name": "user_tmp_uq_%s" % config.ident, + } + ], + ) @testing.requires.temp_table_reflect_indexes def test_get_temp_table_indexes(self): |
