[Sqlalchemy-tickets] Issue #3949: sqlalchemy compiler.py bug (zzzeek/sqlalchemy)
Brought to you by:
zzzeek
From: Jorge S. <iss...@bi...> - 2017-03-29 01:13:04
|
New issue 3949: sqlalchemy compiler.py bug https://bitbucket.org/zzzeek/sqlalchemy/issues/3949/sqlalchemy-compilerpy-bug Jorge Sierra: conn_str = string.Template('db2+ibm_db://$user:$password@localhost:50000/Sample').substitute(user = user , password = password) for t in metadata.sorted_tables: logger.info ("CreateTable %s %s" % (t.name, **CreateTable**(t).compile(db2))) When trying to run **CreateTable** C:\Python27\Lib\site-packages\sqlalchemy\sql\**compiler.py** around line 2588 under function def **visit_foreign_key_constraint**(self, constraint): this function is assuming **f.parent** is never 'None' and in my case it was, same as **f.column** This is the fix below ``` #!python list_text1 = [] for f in constraint.elements: if f.parent is not None: list_text1.append(preparer.quote(f.parent.name)) list_text2 = [] for f in constraint.elements: if hasattr(f, 'column'): if f.column is not None: list_text2.append(preparer.quote(f.column.name)) text += "FOREIGN KEY(%s) REFERENCES %s (%s)" % ( ', '.join(list_text1), self.define_constraint_remote_table( constraint, remote_table, preparer), ', '.join(list_text2)) text += self.define_constraint_match(constraint) text += self.define_constraint_cascades(constraint) text += self.define_constraint_deferrability(constraint) return text ``` |