cannot copy ForeignKeyConstraint(schema=None) as _get_colspec interprets None as a default

Issue #1673 resolved
Paul Harrington created an issue

This bit me when trying to adapt some SQL Server collections which have a schema to a SQLite database that does not. Here is a workaround which I came up with to allow me to copy a collection of tables.

pjjH

We can't use None as the sentinal value as there are times when we

really do want to zap out the schema part. So use a value that is

unlikely to ever be a valid schema name.

def hacked_get_colspec(element, schema='BOGUS_DEFAULT'): if not schema == 'BOGUS_DEFAULT': if schema is not None: return schema + "." + element.column.table.name + "." + element.column.key else: return element.column.table.name + "." + element.column.key

Comments (5)

  1. Mike Bayer repo owner
    • changed milestone to 0.6.1

    this patch should work. needs unit tests in test/engine/test_metadata.

    Index: lib/sqlalchemy/schema.py
    ===================================================================
    --- lib/sqlalchemy/schema.py    (revision 6730)
    +++ lib/sqlalchemy/schema.py    (working copy)
    @@ -43,6 +43,8 @@
                ]
     __all__.sort()
    
    +RETAIN_SCHEMA = util.symbol('retain_schema')
    +
     class SchemaItem(visitors.Visitable):
         """Base class for items that define a database schema."""
    
    @@ -413,11 +415,11 @@
             """
             self.metadata.drop_all(bind=bind, checkfirst=checkfirst, tables=[self](self))
    
    -    def tometadata(self, metadata, schema=None):
    +    def tometadata(self, metadata, schema=RETAIN_SCHEMA):
             """Return a copy of this ``Table`` associated with a different ``MetaData``."""
    
             try:
    -            if not schema:
    +            if schema is RETAIN_SCHEMA:
                     schema = self.schema
                 key = _get_table_key(self.name, schema)
                 return metadata.tables[key](key)
    
  2. Log in to comment