<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_dimension(dimension,**kwargs):
 """ Update a dimension in the DB. Raises and exception if the dimension does not exist. The key is ALWAYS the name and the name itself is not modificable """

    db_dimension = None
    dimension = JSONObject(dimension)
    try:
        db_dimension = db.DBSession.query(Dimension).filter(Dimension.id==dimension.id).filter().one()

        if "description" in dimension and dimension["description"] is not None:
            db_dimension.description = dimension["description"]
        if "project_id" in dimension and dimension["project_id"] is not None and dimension["project_id"] != "" and dimension["project_id"].isdigit():
            db_dimension.project_id = dimension["project_id"]
    except NoResultFound:
        raise ResourceNotFoundError("Dimension (ID=%s) does not exist"%(dimension.id))


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