summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/dialects/postgresql/base.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2011-10-29 17:38:56 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2011-10-29 17:38:56 -0400
commite6a5ea8fa7d10078c8d3f1bf6cabc4399cac3e70 (patch)
tree316f3c5287a1389d214437dadb9c2dca0560410f /lib/sqlalchemy/dialects/postgresql/base.py
parent5d6376fbd5ca4103a26118a6fffd1e95be0d5161 (diff)
downloadsqlalchemy-e6a5ea8fa7d10078c8d3f1bf6cabc4399cac3e70.tar.gz
- [bug] Postgresql dialect memoizes that an ENUM of a
particular name was processed during a create/drop sequence. This allows a create/drop sequence to work without any calls to "checkfirst", and also means with "checkfirst" turned on it only needs to check for the ENUM once. [ticket:2311]
Diffstat (limited to 'lib/sqlalchemy/dialects/postgresql/base.py')
-rw-r--r--lib/sqlalchemy/dialects/postgresql/base.py39
1 files changed, 32 insertions, 7 deletions
diff --git a/lib/sqlalchemy/dialects/postgresql/base.py b/lib/sqlalchemy/dialects/postgresql/base.py
index 3ae60f696..e3beeab79 100644
--- a/lib/sqlalchemy/dialects/postgresql/base.py
+++ b/lib/sqlalchemy/dialects/postgresql/base.py
@@ -449,15 +449,40 @@ class ENUM(sqltypes.Enum):
bind.dialect.has_type(bind, self.name, schema=self.schema):
bind.execute(DropEnumType(self))
- def _on_table_create(self, event, target, bind, **kw):
- self.create(bind=bind, checkfirst=True)
+ def _check_for_name_in_memos(self, checkfirst, kw):
+ """Look in the 'ddl runner' for 'memos', then
+ note our name in that collection.
+
+ This to ensure a particular named enum is operated
+ upon only once within any kind of create/drop
+ sequence without relying upon "checkfirst".
- def _on_metadata_create(self, event, target, bind, **kw):
- if self.metadata is not None:
- self.create(bind=bind, checkfirst=True)
+ """
+
+ if '_ddl_runner' in kw:
+ ddl_runner = kw['_ddl_runner']
+ if '_pg_enums' in ddl_runner.memo:
+ pg_enums = ddl_runner.memo['_pg_enums']
+ else:
+ pg_enums = ddl_runner.memo['_pg_enums'] = set()
+ present = self.name in pg_enums
+ pg_enums.add(self.name)
+ return present
+ else:
+ return False
+
+ def _on_table_create(self, target, bind, checkfirst, **kw):
+ if not self._check_for_name_in_memos(checkfirst, kw):
+ 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):
+ self.create(bind=bind, checkfirst=checkfirst)
- def _on_metadata_drop(self, event, target, bind, **kw):
- self.drop(bind=bind, checkfirst=True)
+ def _on_metadata_drop(self, target, bind, checkfirst, **kw):
+ if not self._check_for_name_in_memos(checkfirst, kw):
+ self.drop(bind=bind, checkfirst=checkfirst)
colspecs = {
sqltypes.Interval:INTERVAL,