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 /lib/sqlalchemy | |
| 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 'lib/sqlalchemy')
| -rw-r--r-- | lib/sqlalchemy/sql/sqltypes.py | 6 | ||||
| -rw-r--r-- | lib/sqlalchemy/sql/type_api.py | 16 |
2 files changed, 12 insertions, 10 deletions
diff --git a/lib/sqlalchemy/sql/sqltypes.py b/lib/sqlalchemy/sql/sqltypes.py index a73c61147..367b2e203 100644 --- a/lib/sqlalchemy/sql/sqltypes.py +++ b/lib/sqlalchemy/sql/sqltypes.py @@ -1092,7 +1092,7 @@ class SchemaType(SchemaEventTarget): util.portable_instancemethod(self._on_metadata_drop), ) - def _set_parent(self, column): + def _set_parent(self, column, **kw): column._on_table_attach(util.portable_instancemethod(self._set_table)) def _variant_mapping_for_set_table(self, column): @@ -2857,11 +2857,11 @@ class ARRAY(SchemaEventTarget, Indexable, Concatenable, TypeEngine): def compare_values(self, x, y): return x == y - def _set_parent(self, column): + def _set_parent(self, column, **kw): """Support SchemaEventTarget""" if isinstance(self.item_type, SchemaEventTarget): - self.item_type._set_parent(column) + self.item_type._set_parent(column, **kw) def _set_parent_with_dispatch(self, parent): """Support SchemaEventTarget""" diff --git a/lib/sqlalchemy/sql/type_api.py b/lib/sqlalchemy/sql/type_api.py index 9752750c5..bfce00cb5 100644 --- a/lib/sqlalchemy/sql/type_api.py +++ b/lib/sqlalchemy/sql/type_api.py @@ -1063,18 +1063,20 @@ class TypeDecorator(SchemaEventTarget, TypeEngine): """ return self.impl._type_affinity - def _set_parent(self, column): + def _set_parent(self, column, outer=False, **kw): """Support SchemaEventTarget""" super(TypeDecorator, self)._set_parent(column) - if isinstance(self.impl, SchemaEventTarget): - self.impl._set_parent(column) + if not outer and isinstance(self.impl, SchemaEventTarget): + self.impl._set_parent(column, outer=False, **kw) def _set_parent_with_dispatch(self, parent): """Support SchemaEventTarget""" - super(TypeDecorator, self)._set_parent_with_dispatch(parent) + super(TypeDecorator, self)._set_parent_with_dispatch( + parent, outer=True + ) if isinstance(self.impl, SchemaEventTarget): self.impl._set_parent_with_dispatch(parent) @@ -1495,14 +1497,14 @@ class Variant(TypeDecorator): else: return self.impl - def _set_parent(self, column): + def _set_parent(self, column, **kw): """Support SchemaEventTarget""" if isinstance(self.impl, SchemaEventTarget): - self.impl._set_parent(column) + self.impl._set_parent(column, **kw) for impl in self.mapping.values(): if isinstance(impl, SchemaEventTarget): - impl._set_parent(column) + impl._set_parent(column, **kw) def _set_parent_with_dispatch(self, parent): """Support SchemaEventTarget""" |
