def check_type_compatibility(type_1_id, type_2_id):
    """
        When applying a type to a resource, it may be the case that the resource already
        has an attribute specified in the new type, but the template which defines this
        pre-existing attribute has a different unit specification to the new template.

        This function checks for any situations where different types specify the same
        attributes, but with different units.
    """
    errors = []

    type_1 = db.DBSession.query(TemplateType).filter(TemplateType.id==type_1_id).options(joinedload_all('typeattrs')).one()
    type_2 = db.DBSession.query(TemplateType).filter(TemplateType.id==type_2_id).options(joinedload_all('typeattrs')).one()
    template_1_name = type_1.template.name
    template_2_name = type_2.template.name

    type_1_attrs=set([t.attr_id for t in type_1.typeattrs])
    type_2_attrs=set([t.attr_id for t in type_2.typeattrs])

    shared_attrs = type_1_attrs.intersection(type_2_attrs)

    if len(shared_attrs) == 0:
        return []

    type_1_dict = {}
    for t in type_1.typeattrs:
        if t.attr_id in shared_attrs:
            type_1_dict[t.attr_id]=t

    for ta in type_2.typeattrs:
        type_2_unit_id = ta.unit_id
        type_1_unit_id = type_1_dict[ta.attr_id].unit_id

        fmt_dict = {
                    'template_1_name': template_1_name,
                    'template_2_name': template_2_name,
                    'attr_name':       ta.attr.name,
                    'type_1_unit_id':  type_1_unit_id,
                    'type_2_unit_id':  type_2_unit_id,
                    'type_name' :      type_1.name
                }

        if type_1_unit_id is None and type_2_unit_id is not None:
            errors.append("Type %(type_name)s in template %(template_1_name)s"
                          " stores %(attr_name)s with no units, while template"
                          "%(template_2_name)s stores it with unit %(type_2_unit_id)s"%fmt_dict)
        elif type_1_unit_id is not None and type_2_unit_id is None:
            errors.append("Type %(type_name)s in template %(template_1_name)s"
                          " stores %(attr_name)s in %(type_1_unit_id)s."
                          " Template %(template_2_name)s stores it with no unit."%fmt_dict)
        elif type_1_unit_id != type_2_unit_id:
            errors.append("Type %(type_name)s in template %(template_1_name)s"
                          " stores %(attr_name)s in %(type_1_unit_id)s, while"
                          " template %(template_2_name)s stores it in %(type_2_unit_id)s"%fmt_dict)
        return errors
When applying a type to a resource, it may be the case that the resource already
        has an attribute specified in the new type, but the template which defines this
        pre-existing attribute has a different unit specification to the new template.

        This function checks for any situations where different types specify the same
        attributes, but with different units.