def _collect_insert_commands(
        table, states_to_insert,
        bulk=False, return_defaults=False):
    for state, state_dict, mapper, connection in states_to_insert:
        if table not in mapper._pks_by_table:
            continue

        params = {}
        value_params = {}

        propkey_to_col = mapper._propkey_to_col[table]

        eval_none = mapper._insert_cols_evaluating_none[table]

        for propkey in set(propkey_to_col).intersection(state_dict):
            value = state_dict[propkey]
            col = propkey_to_col[propkey]
            if value is None and propkey not in eval_none:
                continue
            elif not bulk and isinstance(value, sql.ClauseElement):
                value_params[col.key] = value
            else:
                params[col.key] = value

        if not bulk:
            for colkey in mapper._insert_cols_as_none[table].\
                    difference(params).difference(value_params):
                params[colkey] = None

        if not bulk or return_defaults:
            has_all_pks = mapper._pk_keys_by_table[table].issubset(params)

            if mapper.base_mapper.eager_defaults:
                has_all_defaults = mapper._server_default_cols[table].\
                    issubset(params)
            else:
                has_all_defaults = True
        else:
            has_all_defaults = has_all_pks = True

        if mapper.version_id_generator is not False \
                and mapper.version_id_col is not None and \
                mapper.version_id_col in mapper._cols_by_table[table]:
            params[mapper.version_id_col.key] = \
                mapper.version_id_generator(None)

        yield (
            state, state_dict, params, mapper,
            connection, value_params, has_all_pks,
            has_all_defaults)
.. todo::
dataset/ETHPy150Open zzzeek/sqlalchemy/lib/sqlalchemy/orm/persistence.py/_collect_insert_commands--crossover with--dataset/ETHPy150Open lisa-lab/pylearn2/pylearn2/models/dbm/dbm.py/DBM.get_weights_view_shape