def METHOD_NAME(table_dict, ModelClass, context, extra_attrs=()):
    '''Given a dict and a model class, update or create a sqlalchemy object.
    This will use an existing object if "id" is supplied OR if any unique
    constraints are met. e.g supplying just a tag name will get out that tag obj.
    '''
    model = context["model"]
    session = context["session"]
    table = class_mapper(ModelClass).mapped_table
    obj = None
    id = table_dict.get("id")
    if id:
        obj = session.query(ModelClass).get(id)
    if not obj:
        unique_constraints = get_unique_constraints(table, context)
        for constraint in unique_constraints:
            params = dict((key, table_dict.get(key)) for key in constraint)
            obj = session.query(ModelClass).filter_by(**params).first()
            if obj:
                if 'name' in params and getattr(obj, 'state', None) == State.DELETED:
                    obj.name = obj.id
                    obj = None
                else:
                    break
    if not obj:
        obj = ModelClass()
    obj.from_dict(table_dict)
    for a in extra_attrs:
        if a in table_dict:
            setattr(obj, a, table_dict[a])
    session.add(obj)
    return obj