diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2021-03-29 17:57:20 -0400 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2021-03-30 10:00:58 -0400 |
| commit | 3d284bb1010996ef204c85a2141446e47d048dac (patch) | |
| tree | 60edea427f0c4eda150c0772ba5e7a3a5b594195 /test/sql | |
| parent | 2c2e01a0c6d0847f5648fd0120c8fa0bd5f6268f (diff) | |
| download | sqlalchemy-3d284bb1010996ef204c85a2141446e47d048dac.tar.gz | |
TypeDecorator passes "outer" flag to itself for set_parent accounting
Fixed bug first introduced in as some combination of :ticket:`2892`,
:ticket:`2919` nnd :ticket:`3832` where the attachment events for a
:class:`_types.TypeDecorator` would be doubled up against the "impl" class,
if the "impl" were also a :class:`_types.SchemaType`. The real-world case
is any :class:`_types.TypeDecorator` against :class:`_types.Enum` or
:class:`_types.Boolean` would get a doubled
:class:`_schema.CheckConstraint` when the ``create_constraint=True`` flag
is set.
Fixes: #6152
Change-Id: I3218b7081297270c132421f6765b5c3673d10a5c
Diffstat (limited to 'test/sql')
| -rw-r--r-- | test/sql/test_metadata.py | 38 | ||||
| -rw-r--r-- | test/sql/test_types.py | 11 |
2 files changed, 24 insertions, 25 deletions
diff --git a/test/sql/test_metadata.py b/test/sql/test_metadata.py index 3e5f7b916..eb5e305a2 100644 --- a/test/sql/test_metadata.py +++ b/test/sql/test_metadata.py @@ -2090,6 +2090,7 @@ class SchemaTypeTest(fixtures.TestBase): def test_before_parent_attach_typedec_enclosing_schematype(self): # additional test for [ticket:2919] as part of test for # [ticket:3832] + # this also serves as the test for [ticket:6152] class MySchemaType(sqltypes.TypeEngine, sqltypes.SchemaType): pass @@ -2100,7 +2101,7 @@ class SchemaTypeTest(fixtures.TestBase): impl = target_typ typ = MyType() - self._test_before_parent_attach(typ, target_typ, double=True) + self._test_before_parent_attach(typ, target_typ) def test_before_parent_attach_array_enclosing_schematype(self): # test for [ticket:4141] which is the same idea as [ticket:3832] @@ -2124,7 +2125,7 @@ class SchemaTypeTest(fixtures.TestBase): typ = MyType() self._test_before_parent_attach(typ) - def _test_before_parent_attach(self, typ, evt_target=None, double=False): + def _test_before_parent_attach(self, typ, evt_target=None): canary = mock.Mock() if evt_target is None: @@ -2133,8 +2134,8 @@ class SchemaTypeTest(fixtures.TestBase): orig_set_parent = evt_target._set_parent orig_set_parent_w_dispatch = evt_target._set_parent_with_dispatch - def _set_parent(parent): - orig_set_parent(parent) + def _set_parent(parent, **kw): + orig_set_parent(parent, **kw) canary._set_parent(parent) def _set_parent_w_dispatch(parent): @@ -2149,27 +2150,14 @@ class SchemaTypeTest(fixtures.TestBase): c = Column("q", typ) - if double: - # no clean way yet to fix this, inner schema type is called - # twice, but this is a very unusual use case. - eq_( - canary.mock_calls, - [ - mock.call._set_parent(c), - mock.call.go(evt_target, c), - mock.call._set_parent(c), - mock.call._set_parent_with_dispatch(c), - ], - ) - else: - eq_( - canary.mock_calls, - [ - mock.call.go(evt_target, c), - mock.call._set_parent(c), - mock.call._set_parent_with_dispatch(c), - ], - ) + eq_( + canary.mock_calls, + [ + mock.call.go(evt_target, c), + mock.call._set_parent(c), + mock.call._set_parent_with_dispatch(c), + ], + ) def test_independent_schema(self): m = MetaData() diff --git a/test/sql/test_types.py b/test/sql/test_types.py index 9a5b9d274..08966b38e 100644 --- a/test/sql/test_types.py +++ b/test/sql/test_types.py @@ -833,6 +833,17 @@ class UserDefinedTest( Float().dialect_impl(pg).__class__, ) + @testing.combinations((Boolean,), (Enum,)) + def test_typedecorator_schematype_constraint(self, typ): + class B(TypeDecorator): + impl = typ + + t1 = Table("t1", MetaData(), Column("q", B(create_constraint=True))) + eq_( + len([c for c in t1.constraints if isinstance(c, CheckConstraint)]), + 1, + ) + def test_type_decorator_repr(self): class MyType(TypeDecorator): impl = VARCHAR |
