diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2014-07-13 18:55:18 -0400 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2014-07-13 18:55:18 -0400 |
commit | 071a1830985834efc113f63fa8740c7306e0cae3 (patch) | |
tree | f77bb3d124bebe9e22ad53b859ed4a56ac0d04f0 /lib | |
parent | 6922a56140d9e014e842a60da344bf6be92f9446 (diff) | |
download | sqlalchemy-071a1830985834efc113f63fa8740c7306e0cae3.tar.gz |
- Fixed bug in :class:`.Enum` and other :class:`.SchemaType`
subclasses where direct association of the type with a
:class:`.MetaData` would lead to a hang when events
(like create events) were emitted on the :class:`.MetaData`.
fixes #3124
Diffstat (limited to 'lib')
-rw-r--r-- | lib/sqlalchemy/dialects/postgresql/base.py | 3 | ||||
-rw-r--r-- | lib/sqlalchemy/sql/sqltypes.py | 15 |
2 files changed, 10 insertions, 8 deletions
diff --git a/lib/sqlalchemy/dialects/postgresql/base.py b/lib/sqlalchemy/dialects/postgresql/base.py index 2ae71c2a7..8081f75dd 100644 --- a/lib/sqlalchemy/dialects/postgresql/base.py +++ b/lib/sqlalchemy/dialects/postgresql/base.py @@ -1100,8 +1100,7 @@ class ENUM(sqltypes.Enum): self.create(bind=bind, checkfirst=checkfirst) def _on_metadata_create(self, target, bind, checkfirst, **kw): - if self.metadata is not None and \ - not self._check_for_name_in_memos(checkfirst, kw): + if not self._check_for_name_in_memos(checkfirst, kw): self.create(bind=bind, checkfirst=checkfirst) def _on_metadata_drop(self, target, bind, checkfirst, **kw): diff --git a/lib/sqlalchemy/sql/sqltypes.py b/lib/sqlalchemy/sql/sqltypes.py index 671ea1b70..b4d2d2390 100644 --- a/lib/sqlalchemy/sql/sqltypes.py +++ b/lib/sqlalchemy/sql/sqltypes.py @@ -918,6 +918,7 @@ class SchemaType(SchemaEventTarget): self.schema = schema self.metadata = metadata self.inherit_schema = inherit_schema + if self.metadata: event.listen( self.metadata, @@ -967,13 +968,16 @@ class SchemaType(SchemaEventTarget): def adapt(self, impltype, **kw): schema = kw.pop('schema', self.schema) - metadata = kw.pop('metadata', self.metadata) + + # don't associate with MetaData as the hosting type + # is already associated with it, avoid creating event + # listeners + metadata = kw.pop('metadata', None) return impltype(name=self.name, schema=schema, metadata=metadata, inherit_schema=self.inherit_schema, - **kw - ) + **kw) @property def bind(self): @@ -1136,7 +1140,7 @@ class Enum(String, SchemaType): def adapt(self, impltype, **kw): schema = kw.pop('schema', self.schema) - metadata = kw.pop('metadata', self.metadata) + metadata = kw.pop('metadata', None) if issubclass(impltype, Enum): return impltype(name=self.name, schema=schema, @@ -1145,8 +1149,7 @@ class Enum(String, SchemaType): native_enum=self.native_enum, inherit_schema=self.inherit_schema, *self.enums, - **kw - ) + **kw) else: return super(Enum, self).adapt(impltype, **kw) |