diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2016-10-20 10:24:40 -0400 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2016-10-20 14:14:50 -0400 |
| commit | 30bd28fca2091e4b2b093154a14c668c09ae3ccd (patch) | |
| tree | 3fe9647770d95e31f0a4cb2695ae9738cf6df372 /test/sql/test_metadata.py | |
| parent | 39ac19510989390dddf7a51f65ec7c8830ec04d1 (diff) | |
| download | sqlalchemy-30bd28fca2091e4b2b093154a14c668c09ae3ccd.tar.gz | |
Ensure TypeDecorator delegates _set_parent_with_dispatch
Ensure TypeDecorator delegates _set_parent_with_dispatch as well as
_set_parent to itself as well as its impl, as the TypeDecorator
class itself may have an active SchemaType implementation as well.
Fixed regression which occurred as a side effect of :ticket:`2919`,
which in the less typical case of a user-defined
:class:`.TypeDecorator` that was also itself an instance of
:class:`.SchemaType` (rather than the implementation being such)
would cause the column attachment events to be skipped for the
type itself.
Change-Id: I0afb498fd91ab7d948e4439e7323a89eafcce0bc
Fixes: #3832
Diffstat (limited to 'test/sql/test_metadata.py')
| -rw-r--r-- | test/sql/test_metadata.py | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/test/sql/test_metadata.py b/test/sql/test_metadata.py index f2df4da06..f790c2aa0 100644 --- a/test/sql/test_metadata.py +++ b/test/sql/test_metadata.py @@ -1574,6 +1574,66 @@ class SchemaTypeTest(fixtures.TestBase): class MyTypeImpl(MyTypeWImpl): pass + class MyTypeDecAndSchema(TypeDecorator, sqltypes.SchemaType): + impl = String() + + evt_targets = () + + def __init__(self): + TypeDecorator.__init__(self) + sqltypes.SchemaType.__init__(self) + + def _on_table_create(self, target, bind, **kw): + self.evt_targets += (target,) + + def _on_metadata_create(self, target, bind, **kw): + self.evt_targets += (target,) + + def test_before_parent_attach_plain(self): + typ = self.MyType() + self._test_before_parent_attach(typ) + + def test_before_parent_attach_typedec_enclosing_schematype(self): + # additional test for [ticket:2919] as part of test for + # [ticket:3832] + + class MySchemaType(sqltypes.TypeEngine, sqltypes.SchemaType): + pass + + target_typ = MySchemaType() + + class MyType(TypeDecorator): + impl = target_typ + + typ = MyType() + self._test_before_parent_attach(typ, target_typ) + + def test_before_parent_attach_typedec_of_schematype(self): + class MyType(TypeDecorator, sqltypes.SchemaType): + impl = String + + typ = MyType() + self._test_before_parent_attach(typ) + + def test_before_parent_attach_schematype_of_typedec(self): + class MyType(sqltypes.SchemaType, TypeDecorator): + impl = String + + typ = MyType() + self._test_before_parent_attach(typ) + + def _test_before_parent_attach(self, typ, evt_target=None): + canary = mock.Mock() + + if evt_target is None: + evt_target = typ + + event.listen(evt_target, "before_parent_attach", canary.go) + + c = Column('q', typ) + + eq_(canary.mock_calls, [mock.call.go(evt_target, c)]) + def test_independent_schema(self): m = MetaData() type_ = self.MyType(schema="q") @@ -1709,6 +1769,13 @@ class SchemaTypeTest(fixtures.TestBase): dialect_impl = typ.dialect_impl(testing.db.dialect) eq_(dialect_impl.evt_targets, (m1, )) + def test_table_dispatch_decorator_schematype(self): + m1 = MetaData() + typ = self.MyTypeDecAndSchema() + t1 = Table('t1', m1, Column('x', typ)) + m1.dispatch.before_create(t1, testing.db) + eq_(typ.evt_targets, (t1, )) + def test_table_dispatch_no_new_impl(self): m1 = MetaData() typ = self.MyType() |
