<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(self, cls, rid, partialrecord, user='undefined'):
 """Update existing record 25 'jane' Traceback (most recent call last):
 KeyError: 'No such record' Traceback (most recent call last):
 KeyError: 'There is already a record for tstoretest/1' Traceback (most recent call last):
 ValueError: Undefined field Traceback (most recent call last):
 ValueError: Bad update (INVALID_TEXT_REPRESENTATION) """

        self.validate_partial_record(cls, partialrecord)
        partialrecord[UPDATE_DATE] = self.nowstr()
        partialrecord[UPDATER] = user
        try:
            updatecount = self.db.update(cls, partialrecord, where={ID: rid})
            if updatecount < 1:
                raise KeyError('No such record')
        except (psycopg2.IntegrityError, psycopg2.ProgrammingError,
                psycopg2.DataError) as error:
            if error.pgcode == psycopg2.errorcodes.UNIQUE_VIOLATION:
                raise KeyError('There is already a record for {}/{}'.format(
                    cls, partialrecord[ID]))
            elif error.pgcode == psycopg2.errorcodes.UNDEFINED_COLUMN:
                raise ValueError('Undefined field')
            else:
                raise ValueError('Bad update ({})'.format(
                    psycopg2.errorcodes.lookup(error.pgcode)))