# Buggy code
def _set_parent(self, table):
    ColumnCollectionMixin._set_parent(self, table)

    if self.table is not None and table is not self.table:
        raise exc.ArgumentError(
            "Index '%s' is against table '%s', and "
            "cannot be associated with table '%s'."
            % (self.name, self.table.description, table.description)
        )
    self.table = table
    table.indexes.add(self)

    self.expressions = [
        expr if isinstance(expr, ClauseElement) else colexpr
        for expr, colexpr in util.zip_longest(self.expressions, self.columns)
    ]


# 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 _set_parent(self, table):
    ColumnCollectionMixin._set_parent(self, table)

    if self.table is not None and table is not self.table:
        raise exc.ArgumentError(
            "Index '%s' is against table '%s', and "
            "cannot be associated with table '%s'."
            % (self.name, self.table.description, table.description)
        )
    self.table = table
    table.indexes.add(self)

    expressions = self.expressions
    col_expressions = self._col_expressions(table)
    assert len(expressions) == len(col_expressions)
    self.expressions = [
        expr if isinstance(expr, ClauseElement) else colexpr
        for expr, colexpr in zip(expressions, col_expressions)
    ]