From 7c55d3dab0e7f477c0a5961e6ee9fb034e759aa4 Mon Sep 17 00:00:00 2001 From: Marcin Kuzminski Date: Tue, 14 Jul 2020 10:40:05 +0200 Subject: [PATCH] comments-api: make edit API resilent to bad version data. --- rhodecode/model/comment.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/rhodecode/model/comment.py b/rhodecode/model/comment.py index 556232a5..dd9f7ad5 100644 --- a/rhodecode/model/comment.py +++ b/rhodecode/model/comment.py @@ -34,7 +34,7 @@ from sqlalchemy.sql.functions import coalesce from rhodecode.lib import helpers as h, diffs, channelstream, hooks_utils from rhodecode.lib import audit_logger from rhodecode.lib.exceptions import CommentVersionMismatch -from rhodecode.lib.utils2 import extract_mentioned_users, safe_str +from rhodecode.lib.utils2 import extract_mentioned_users, safe_str, safe_int from rhodecode.model import BaseModel from rhodecode.model.db import ( ChangesetComment, @@ -504,12 +504,16 @@ class CommentsModel(BaseModel): old_comment_text = comment.text comment.text = text comment.modified_at = datetime.datetime.now() + version = safe_int(version) + # NOTE(marcink): this returns initial comment + edits, so v2 from ui + # would return 3 here comment_version = ChangesetCommentHistory.get_version(comment_id) - if (comment_version - version) != 1: + + if isinstance(version, (int, long)) and (comment_version - version) != 1: log.warning( 'Version mismatch comment_version {} submitted {}, skipping'.format( - comment_version, + comment_version-1, # -1 since note above version ) )