# Buggy code
def visit_unique_constraint(self, constraint):
    text = super(SQLiteDDLCompiler, self).visit_unique_constraint(constraint)

    on_conflict_clause = constraint.dialect_options["sqlite"]["on_conflict"]
    if on_conflict_clause is None and len(constraint.columns) == 1:
        on_conflict_clause = list(constraint)[0].dialect_options["sqlite"][
            "on_conflict_unique"
        ]

    if on_conflict_clause is not None:
        text += " ON CONFLICT " + on_conflict_clause

    return text


# Traceback (KeyError)
=============================================== FAILURES ================================================
_________________________________ ToMetaDataExcludeConstraint.test_copy _________________________________
Traceback (most recent call last):
File "/home/jeffh/workspace/vortex-workspace/vfinance/subrepos/SQLAlchemy-1.3.18/test/sql/test_metadata.py", line 5238, in test_copy
table_c = table.tometadata(meta2)
File "/home/jeffh/workspace/vortex-workspace/vfinance/subrepos/SQLAlchemy-1.3.18/test/../lib/sqlalchemy/sql/schema.py", line 1063, in tometadata
table.append_constraint(
File "/home/jeffh/workspace/vortex-workspace/vfinance/subrepos/SQLAlchemy-1.3.18/test/../lib/sqlalchemy/sql/schema.py", line 867, in append_constraint
constraint._set_parent_with_dispatch(self)
File "/home/jeffh/workspace/vortex-workspace/vfinance/subrepos/SQLAlchemy-1.3.18/test/../lib/sqlalchemy/sql/base.py", line 463, in _set_parent_with_dispatch
self._set_parent(parent)
File "/home/jeffh/workspace/vortex-workspace/vfinance/subrepos/SQLAlchemy-1.3.18/test/../lib/sqlalchemy/sql/schema.py", line 3065, in _set_parent
ColumnCollectionMixin._set_parent(self, table)
File "/home/jeffh/workspace/vortex-workspace/vfinance/subrepos/SQLAlchemy-1.3.18/test/../lib/sqlalchemy/sql/schema.py", line 3022, in _set_parent
for col in self._col_expressions(table):
File "/home/jeffh/workspace/vortex-workspace/vfinance/subrepos/SQLAlchemy-1.3.18/test/../lib/sqlalchemy/sql/schema.py", line 3016, in _col_expressions
return [
File "/home/jeffh/workspace/vortex-workspace/vfinance/subrepos/SQLAlchemy-1.3.18/test/../lib/sqlalchemy/sql/schema.py", line 3017, in <listcomp>
table.c[col] if isinstance(col, util.string_types) else col
File "/home/jeffh/workspace/vortex-workspace/vfinance/subrepos/SQLAlchemy-1.3.18/test/../lib/sqlalchemy/util/_collections.py", line 194, in __getitem__
return self._data[key]
KeyError: "daterange(valid_from_date, valid_thru_date, '[]')"
======================================== short test summary info ========================================
FAILED test/sql/test_metadata.py::ToMetaDataExcludeConstraint::test_copy - KeyError: "daterange(valid_...

# Fixed code
def visit_unique_constraint(self, constraint):
    text = super(SQLiteDDLCompiler, self).visit_unique_constraint(constraint)

    on_conflict_clause = constraint.dialect_options["sqlite"]["on_conflict"]
    if on_conflict_clause is None and len(constraint.columns) == 1:
        col1 = list(constraint)[0]
        if isinstance(col1, schema.SchemaItem):
            on_conflict_clause = list(constraint)[0].dialect_options["sqlite"][
                "on_conflict_unique"
            ]

    if on_conflict_clause is not None:
        text += " ON CONFLICT " + on_conflict_clause

    return text