<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def update_unit(unit, **kwargs):
 """ Update a unit in the DB. Raises and exception if the unit does not exist """

    try:

        db_unit = db.DBSession.query(Unit).join(Dimension).filter(Unit.id==unit["id"]).filter().one()

        db_unit.name = unit["name"]

        # Needed to uniform into to description
        db_unit.abbreviation = unit.abbreviation
        db_unit.description = unit.description

        db_unit.lf = unit["lf"]
        db_unit.cf = unit["cf"]
        if "project_id" in unit and unit['project_id'] is not None and unit['project_id'] != "":
            db_unit.project_id = unit["project_id"]
    except NoResultFound:
        raise ResourceNotFoundError("Unit (ID=%s) does not exist"%(unit["id"]))


    db.DBSession.flush()
    return JSONObject(db_unit)