def set_publication_failure(cursor, exc):
publication_id = exc.publication_id<EOL>if publication_id is None:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>cursor.execute("""<STR_LIT>""", (publication_id,))<EOL>state_messages = cursor.fetchone()[<NUM_LIT:0>]<EOL>if state_messages is None:<EOL><INDENT>state_messages = []<EOL><DEDENT>entry = exc.__dict__<EOL>entry['<STR_LIT:message>'] = exc.message<EOL>state_messages.append(entry)<EOL>state_messages = json.dumps(state_messages)<EOL>cursor.execute("""<STR_LIT>""", ('<STR_LIT>', state_messages, publication_id,))<EOL>
Given a publication exception, set the publication as failed and
    append the failure message to the publication record.