OK I rearranged how PG does "checkfirst", to only process a particular named
ENUM type once within a particular create/drop sequence without needing to
check the DB, so the "checkfirst" flag can now be honored normally. This is in
rde4eb56fb6c8 and you can get this at
http://hg.sqlalchemy.org/sqlalchemy/archive/de4eb56fb6c8.tar.gz, let me know if
any issues remain, thanks !
On Oct 28, 2011, at 1:57 PM, Michael Bayer wrote:
> I can make a ticket for this since the Enum type is using the deprecated
> event system and PG's event here doesn't have access to the "checkfirst"
> flag. Ticket #2311. For now you'd have to not use the "native" enum type
> with PG, or patch out that "checkfirst=True" inside of postgresql/base.py,
> since that is the source of the issue.
>
>
> On Oct 28, 2011, at 10:52 AM, lestat wrote:
>
>> If I do this:
>>
>> from sqlalchemy import *
>> from StringIO import StringIO
>> buf = StringIO()
>> pg_engine = create_engine('sqlite://', strategy='mock',
>> executor=lambda s,p=';': buf.write(s.__str__() + p))
>> buf.truncate(0)
>> tables = [x[1] for x in sorted(db.metadata.tables.items(), key=lambda
>> x: x[0])]
>> for table in tables:
>> table.create(pg_engine)
>> print buf.getvalue()
>>
>> ok, it prints,
>>
>> but if I change engine to 'postgres://'
>> then sqlalchemy print error:
>>
>> ---------------------------------------------------------------------------
>> AttributeError Traceback (most recent call
>> last)
>>
>>
>> 59 tables = [x[1] for x in sorted(db.metadata.tables.items(),
>> key=lambda x: x[0])]
>> 60 for table in tables:
>> ---> 61 table.create(pg_engine)
>> 62 print buf.getvalue()
>> 63
>>
>> /usr/lib/python2.7/site-packages/sqlalchemy/schema.pyc in create(self,
>> bind, checkfirst)
>> 525 bind._run_visitor(ddl.SchemaGenerator,
>> 526 self,
>> --> 527 checkfirst=checkfirst)
>> 528
>> 529
>>
>> /usr/lib/python2.7/site-packages/sqlalchemy/engine/strategies.pyc in
>> _run_visitor(self, visitorcallable, element, connection, **kwargs)
>> 247 kwargs['checkfirst'] = False
>> 248 visitorcallable(self.dialect, self,
>> --> 249 **kwargs).traverse(element)
>> 250
>> 251 def execute(self, object, *multiparams, **params):
>>
>> /usr/lib/python2.7/site-packages/sqlalchemy/sql/visitors.pyc in
>> traverse(self, obj)
>> 94 """traverse and visit the given expression
>> structure."""
>> 95
>> ---> 96 return traverse(obj, self.__traverse_options__,
>> self._visitor_dict)
>> 97
>> 98 @util.memoized_property
>>
>> /usr/lib/python2.7/site-packages/sqlalchemy/sql/visitors.pyc in
>> traverse(obj, opts, visitors)
>> 205 """traverse and visit the given expression structure using
>> the default iterator."""
>> 206
>> --> 207 return traverse_using(iterate(obj, opts), obj, visitors)
>> 208
>> 209 def traverse_depthfirst(obj, opts, visitors):
>>
>> /usr/lib/python2.7/site-packages/sqlalchemy/sql/visitors.pyc in
>> traverse_using(iterator, obj, visitors)
>> 199 meth = visitors.get(target.__visit_name__, None)
>> 200 if meth:
>> --> 201 meth(target)
>> 202 return obj
>> 203
>>
>> /usr/lib/python2.7/site-packages/sqlalchemy/engine/ddl.pyc in
>> visit_table(self, table, create_ok)
>> 74
>> 75 table.dispatch.before_create(table, self.connection,
>> ---> 76
>> checkfirst=self.checkfirst)
>> 77
>> 78 for column in table.columns:
>>
>> /usr/lib/python2.7/site-packages/sqlalchemy/event.pyc in
>> __call__(self, *args, **kw)
>> 272 fn(*args, **kw)
>> 273 for fn in self.listeners:
>> --> 274 fn(*args, **kw)
>> 275
>> 276 # I'm not entirely thrilled about the overhead here,
>>
>> /usr/lib/python2.7/site-packages/sqlalchemy/schema.pyc in
>> adapt_listener(target, connection, **kw)
>> 484
>> 485 def adapt_listener(target, connection, **kw):
>> --> 486 listener(event_name, target, connection)
>> 487
>> 488 event.listen(self, "" + event_name.replace('-', '_'),
>> adapt_listener)
>>
>> /usr/lib/python2.7/site-packages/sqlalchemy/util/langhelpers.pyc in
>> __call__(self, *arg, **kw)
>> 279
>> 280 def __call__(self, *arg, **kw):
>> --> 281 return getattr(self.target, self.name)(*arg, **kw)
>> 282
>> 283 def class_hierarchy(cls):
>>
>> /usr/lib/python2.7/site-packages/sqlalchemy/types.pyc in
>> _on_table_create(self, event, target, bind, **kw)
>> 1676 t = self.dialect_impl(bind.dialect)
>> 1677 if t.__class__ is not self.__class__ and isinstance(t,
>> SchemaType):
>> -> 1678 t._on_table_create(event, target, bind, **kw)
>> 1679
>> 1680 def _on_table_drop(self, event, target, bind, **kw):
>>
>> /usr/lib/python2.7/site-packages/sqlalchemy/dialects/postgresql/
>> base.pyc in _on_table_create(self, event, target, bind, **kw)
>> 451
>> 452 def _on_table_create(self, event, target, bind, **kw):
>> --> 453 self.create(bind=bind, checkfirst=True)
>> 454
>> 455 def _on_metadata_create(self, event, target, bind, **kw):
>>
>> /usr/lib/python2.7/site-packages/sqlalchemy/dialects/postgresql/
>> base.pyc in create(self, bind, checkfirst)
>> 439
>> 440 if not checkfirst or \
>> --> 441 not bind.dialect.has_type(bind, self.name,
>> schema=self.schema):
>> 442 bind.execute(CreateEnumType(self))
>> 443
>>
>> /usr/lib/python2.7/site-packages/sqlalchemy/dialects/postgresql/
>> base.pyc in has_type(self, connection, type_name, schema)
>> 1037 """
>> 1038 cursor = connection.execute(sql.text(query,
>> bindparams=bindparams))
>> -> 1039 return bool(cursor.scalar())
>> 1040
>> 1041 def _get_server_version_info(self, connection):
>>
>> AttributeError: 'NoneType' object has no attribute 'scalar'
>>
>>
>>
>>
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "sqlalchemy" group.
>> To post to this group, send email to [email protected].
>> To unsubscribe from this group, send email to
>> [email protected].
>> For more options, visit this group at
>> http://groups.google.com/group/sqlalchemy?hl=en.
>>
>
> --
> You received this message because you are subscribed to the Google Groups
> "sqlalchemy" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/sqlalchemy?hl=en.
>
--
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/sqlalchemy?hl=en.