def METHOD_NAME(self, session, entity_ids, custom_attr_key_by_id):
    # Prepare values for query
    entity_ids_joined = ",".join([
        '"{}"'.format(entity_id)
        for entity_id in entity_ids
    ])
    conf_ids_joined = ",".join([
        '"{}"'.format(conf_id)
        for conf_id in custom_attr_key_by_id.keys()
    ])
    # Query custom attribute values
    value_items = session.query(
        (
            "select value, entity_id, configuration_id"
            " from CustomAttributeValue"
            " where entity_id in ({}) and configuration_id in ({})"
        ).format(
            entity_ids_joined,
            conf_ids_joined
        )
    ).all()
    # Prepare default value output per entity id
    values_by_key = {
        key: None for key in self.custom_attribute_keys
    }
    # Prepare all entity ids that were queried
    values_by_entity_id = {
        entity_id: copy.deepcopy(values_by_key)
        for entity_id in entity_ids
    }
    # Add none entity id which is used as default value
    values_by_entity_id[None] = copy.deepcopy(values_by_key)
    # Go through queried data and store them
    for item in value_items:
        conf_id = item["configuration_id"]
        conf_key = custom_attr_key_by_id[conf_id]
        entity_id = item["entity_id"]
        values_by_entity_id[entity_id][conf_key] = item["value"]
    return values_by_entity_id