# Buggy code
def _to_schema_column_or_string(element):
    if hasattr(element, "__clause_element__"):
        element = element.__clause_element__()
    if not isinstance(element, util.string_types + (ColumnElement,)):
        msg = "Element %r is not a string name or column element"
        raise exc.ArgumentError(msg % element)
    return element


# Traceback (AttributeError)
Traceback (most recent call last):
File "temp.py", line 24, in <module>
Base.metadata.create_all(engine)
File "/home/jmabey/Code/bug/env/lib/python3.7/site-packages/sqlalchemy/sql/schema.py", line 4287, in create_all
ddl.SchemaGenerator, self, checkfirst=checkfirst, tables=tables
File "/home/jmabey/Code/bug/env/lib/python3.7/site-packages/sqlalchemy/engine/base.py", line 2036, in _run_visitor
conn._run_visitor(visitorcallable, element, **kwargs)
File "/home/jmabey/Code/bug/env/lib/python3.7/site-packages/sqlalchemy/engine/base.py", line 1607, in _run_visitor
visitorcallable(self.dialect, self, **kwargs).traverse_single(element)
File "/home/jmabey/Code/bug/env/lib/python3.7/site-packages/sqlalchemy/sql/visitors.py", line 131, in traverse_single
return meth(obj, **kw)
File "/home/jmabey/Code/bug/env/lib/python3.7/site-packages/sqlalchemy/sql/ddl.py", line 781, in visit_metadata
_is_metadata_operation=True,
File "/home/jmabey/Code/bug/env/lib/python3.7/site-packages/sqlalchemy/sql/visitors.py", line 131, in traverse_single
return meth(obj, **kw)
File "/home/jmabey/Code/bug/env/lib/python3.7/site-packages/sqlalchemy/sql/ddl.py", line 833, in visit_table
self.traverse_single(index)
File "/home/jmabey/Code/bug/env/lib/python3.7/site-packages/sqlalchemy/sql/visitors.py", line 131, in traverse_single
return meth(obj, **kw)
File "/home/jmabey/Code/bug/env/lib/python3.7/site-packages/sqlalchemy/sql/ddl.py", line 862, in visit_index
self.connection.execute(CreateIndex(index))
File "/home/jmabey/Code/bug/env/lib/python3.7/site-packages/sqlalchemy/engine/base.py", line 988, in execute
return meth(self, multiparams, params)
File "/home/jmabey/Code/bug/env/lib/python3.7/site-packages/sqlalchemy/sql/ddl.py", line 72, in _execute_on_connection
return connection._execute_ddl(self, multiparams, params)
File "/home/jmabey/Code/bug/env/lib/python3.7/site-packages/sqlalchemy/engine/base.py", line 1043, in _execute_ddl
else None,
File "<string>", line 1, in <lambda>
File "/home/jmabey/Code/bug/env/lib/python3.7/site-packages/sqlalchemy/sql/elements.py", line 462, in compile
return self._compiler(dialect, bind=bind, **kw)
File "/home/jmabey/Code/bug/env/lib/python3.7/site-packages/sqlalchemy/sql/ddl.py", line 29, in _compiler
return dialect.ddl_compiler(dialect, self, **kw)
File "/home/jmabey/Code/bug/env/lib/python3.7/site-packages/sqlalchemy/sql/compiler.py", line 319, in __init__
self.string = self.process(self.statement, **compile_kwargs)
File "/home/jmabey/Code/bug/env/lib/python3.7/site-packages/sqlalchemy/sql/compiler.py", line 350, in process
return obj._compiler_dispatch(self, **kwargs)
File "/home/jmabey/Code/bug/env/lib/python3.7/site-packages/sqlalchemy/sql/visitors.py", line 91, in _compiler_dispatch
return meth(self, **kw)
File "/home/jmabey/Code/bug/env/lib/python3.7/site-packages/sqlalchemy/dialects/postgresql/base.py", line 1943, in visit_create_index
for expr in index.expressions
File "/home/jmabey/Code/bug/env/lib/python3.7/site-packages/sqlalchemy/dialects/postgresql/base.py", line 1943, in <listcomp>
for expr in index.expressions
AttributeError: 'NoneType' object has no attribute 'self_group'

# Fixed code
def _to_schema_column_or_string(element):
    if element is None:
        return element
    elif hasattr(element, "__clause_element__"):
        element = element.__clause_element__()
    if not isinstance(element, util.string_types + (ColumnElement,)):
        msg = "Element %r is not a string name or column element"
        raise exc.ArgumentError(msg % element)
    return element