diff options
| author | Gord Thompson <gord@gordthompson.com> | 2021-03-06 12:19:13 -0700 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2021-03-06 22:27:59 -0500 |
| commit | 506b88de5e428fd4ad2feff663ba53e2dbb28891 (patch) | |
| tree | 4da8bb1166928480cec3dc9668d1a1a6175dd087 /test/sql | |
| parent | 1f3ef9817453faa021544841d10b5b7107b57916 (diff) | |
| download | sqlalchemy-506b88de5e428fd4ad2feff663ba53e2dbb28891.tar.gz | |
Fix named CHECK constraint name omitted on repeated creates
Fixed issue where the CHECK constraint generated by :class:`_types.Boolean`
or :class:`_types.Enum` would fail to render the naming convention
correctly after the first compilation, due to an unintended change of state
within the name given to the constraint. This issue was first introduced in
0.9 in the fix for issue #3067, and the fix revises the approach taken at
that time which appears to have been more involved than what was needed.
Co-authored-by: Mike Bayer <mike_mp@zzzcomputing.com>
Fixes: #6007
Change-Id: I7ecff0a9d86191520f6841b3922a5af5a6971fba
Diffstat (limited to 'test/sql')
| -rw-r--r-- | test/sql/test_metadata.py | 44 |
1 files changed, 20 insertions, 24 deletions
diff --git a/test/sql/test_metadata.py b/test/sql/test_metadata.py index 2e64e0a90..3e5f7b916 100644 --- a/test/sql/test_metadata.py +++ b/test/sql/test_metadata.py @@ -4926,20 +4926,11 @@ class NamingConventionTest(fixtures.TestBase, AssertsCompiledSQL): dialect="default", ) - def test_uq_defer_name_no_convention(self): - u1 = self._fixture(naming_convention={}) - uq = UniqueConstraint(u1.c.data, name=naming._defer_name("myname")) - self.assert_compile( - schema.AddConstraint(uq), - 'ALTER TABLE "user" ADD CONSTRAINT myname UNIQUE (data)', - dialect="default", - ) - def test_uq_defer_name_convention(self): u1 = self._fixture( naming_convention={"uq": "uq_%(table_name)s_%(column_0_name)s"} ) - uq = UniqueConstraint(u1.c.data, name=naming._defer_name("myname")) + uq = UniqueConstraint(u1.c.data, name=naming._NONE_NAME) self.assert_compile( schema.AddConstraint(uq), 'ALTER TABLE "user" ADD CONSTRAINT uq_user_data UNIQUE (data)', @@ -5139,7 +5130,7 @@ class NamingConventionTest(fixtures.TestBase, AssertsCompiledSQL): u1 = self._fixture( naming_convention={"ck": "ck_%(table_name)s_%(constraint_name)s"} ) - ck = CheckConstraint(u1.c.data == "x", name=naming._defer_name(None)) + ck = CheckConstraint(u1.c.data == "x", name=naming._NONE_NAME) assert_raises_message( exc.InvalidRequestError, @@ -5254,14 +5245,16 @@ class NamingConventionTest(fixtures.TestBase, AssertsCompiledSQL): m1, Column("x", Boolean(name="foo", create_constraint=True)), ) - # constraint is not hit - eq_( - [c for c in u1.constraints if isinstance(c, CheckConstraint)][ - 0 - ].name, - "foo", + + self.assert_compile( + schema.CreateTable(u1), + 'CREATE TABLE "user" (' + "x BOOLEAN, " + "CONSTRAINT ck_user_foo CHECK (x IN (0, 1))" + ")", ) - # but is hit at compile time + + # test no side effects from first compile self.assert_compile( schema.CreateTable(u1), 'CREATE TABLE "user" (' @@ -5302,13 +5295,16 @@ class NamingConventionTest(fixtures.TestBase, AssertsCompiledSQL): m1, Column("x", Enum("a", "b", name="foo", create_constraint=True)), ) - eq_( - [c for c in u1.constraints if isinstance(c, CheckConstraint)][ - 0 - ].name, - "foo", + + self.assert_compile( + schema.CreateTable(u1), + 'CREATE TABLE "user" (' + "x VARCHAR(1), " + "CONSTRAINT ck_user_foo CHECK (x IN ('a', 'b'))" + ")", ) - # but is hit at compile time + + # test no side effects from first compile self.assert_compile( schema.CreateTable(u1), 'CREATE TABLE "user" (' |
