# Buggy code
def process_bind_param(self, value, dialect):
    """Automatically truncate string values"""
    if self.impl.length and value is not None:
        value = value[0 : self.impl.length]
    return value


# Traceback (StatementError)
galaxy.web.framework.decorators ERROR 2019-09-19 17:20:36,279 [p:47682,w:1,m:0] [uWSGIWorker1Core0] Uncaught exception in exposed API method:
Traceback (most recent call last):
File "lib/galaxy/web/framework/decorators.py", line 157, in decorator
rval = func(self, trans, *args, **kwargs)
File "lib/galaxy/webapps/galaxy/controllers/dataset.py", line 426, in set_edit
trans.sa_session.flush()
File "/path/to/galaxy/.venv/lib/python2.7/site-packages/sqlalchemy/orm/scoping.py", line 162, in do
return getattr(self.registry(), name)(*args, **kwargs)
File "/path/to/galaxy/.venv/lib/python2.7/site-packages/sqlalchemy/orm/session.py", line 2459, in flush
self._flush(objects)
File "/path/to/galaxy/.venv/lib/python2.7/site-packages/sqlalchemy/orm/session.py", line 2597, in _flush
transaction.rollback(_capture_exception=True)
File "/path/to/galaxy/.venv/lib/python2.7/site-packages/sqlalchemy/util/langhelpers.py", line 68, in __exit__
compat.reraise(exc_type, exc_value, exc_tb)
File "/path/to/galaxy/.venv/lib/python2.7/site-packages/sqlalchemy/orm/session.py", line 2557, in _flush
flush_context.execute()
File "/path/to/galaxy/.venv/lib/python2.7/site-packages/sqlalchemy/orm/unitofwork.py", line 422, in execute
rec.execute(self)
File "/path/to/galaxy/.venv/lib/python2.7/site-packages/sqlalchemy/orm/unitofwork.py", line 589, in execute
uow,
File "/path/to/galaxy/.venv/lib/python2.7/site-packages/sqlalchemy/orm/persistence.py", line 236, in save_obj
update,
File "/path/to/galaxy/.venv/lib/python2.7/site-packages/sqlalchemy/orm/persistence.py", line 996, in _emit_update_statements
statement, multiparams
File "/path/to/galaxy/.venv/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 988, in execute
return meth(self, multiparams, params)
File "/path/to/galaxy/.venv/lib/python2.7/site-packages/sqlalchemy/sql/elements.py", line 287, in _execute_on_connection
return connection._execute_clauseelement(self, multiparams, params)
File "/path/to/galaxy/.venv/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 1107, in _execute_clauseelement
distilled_params,
File "/path/to/galaxy/.venv/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 1182, in _execute_context
e, util.text_type(statement), parameters, None, None
File "/path/to/galaxy/.venv/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 1466, in _handle_dbapi_exception
util.raise_from_cause(sqlalchemy_exception, exc_info)
File "/path/to/galaxy/.venv/lib/python2.7/site-packages/sqlalchemy/util/compat.py", line 398, in raise_from_cause
reraise(type(exception), exception, tb=exc_tb, cause=cause)
File "/path/to/galaxy/.venv/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 1179, in _execute_context
context = constructor(dialect, self, conn, *args)
File "/path/to/galaxy/.venv/lib/python2.7/site-packages/sqlalchemy/engine/default.py", line 719, in _init_compiled
param.append(processors[key](compiled_params[key]))
File "/path/to/galaxy/.venv/lib/python2.7/site-packages/sqlalchemy/sql/type_api.py", line 1210, in process
return process_param(value, dialect)
File "lib/galaxy/model/custom_types.py", line 375, in process_bind_param
value = value[0:self.impl.length]
StatementError: (exceptions.TypeError) 'int' object has no attribute '__getitem__'
[SQL: UPDATE history_dataset_association SET update_time=?, name=?, metadata=?, version=? WHERE history_dataset_association.id = ?]
[parameters: [{'_metadata': {u'data_lines': 1, u'dbkey': [u'?']}, 'version': 4, 'name': 1, 'history_dataset_association_id': 1234}]]

# Fixed code
def process_bind_param(self, value, dialect):
    """Automatically truncate string values"""
    if self.impl.length and value is not None:
        value = unicodify(value)[0 : self.impl.length]
    return value