# HG changeset patch # User Marcin Kuzminski # Date 2018-01-06 11:08:49 # Node ID 4400cfcf1c119c67aa48dacc0001f046541828ea # Parent da49a829bd3b2c528505398ce8e3b39ff5488ed4 events: properly refresh comment object to load it's relationship. This prevents from issues of reading associated statuses of comment during a partial commit (using Session().flush) - Fixes #5412 diff --git a/rhodecode/apps/repository/views/repo_pull_requests.py b/rhodecode/apps/repository/views/repo_pull_requests.py --- a/rhodecode/apps/repository/views/repo_pull_requests.py +++ b/rhodecode/apps/repository/views/repo_pull_requests.py @@ -1159,6 +1159,10 @@ class RepoPullRequestsView(RepoAppView, ) Session().flush() + # this is somehow required to get access to some relationship + # loaded on comment + Session().refresh(comment) + events.trigger( events.PullRequestCommentEvent(pull_request, comment)) diff --git a/rhodecode/model/changeset_status.py b/rhodecode/model/changeset_status.py --- a/rhodecode/model/changeset_status.py +++ b/rhodecode/model/changeset_status.py @@ -18,16 +18,14 @@ # RhodeCode Enterprise Edition, including its added features, Support services, # and proprietary license terms, please see https://rhodecode.com/licenses/ -""" -Changeset status conttroller -""" import itertools import logging from collections import defaultdict from rhodecode.model import BaseModel -from rhodecode.model.db import ChangesetStatus, ChangesetComment, PullRequest +from rhodecode.model.db import ( + ChangesetStatus, ChangesetComment, PullRequest, Session) from rhodecode.lib.exceptions import StatusChangeOnClosedPullRequestError from rhodecode.lib.markup_renderer import ( DEFAULT_COMMENTS_RENDERER, RstTemplateRenderer) @@ -188,7 +186,7 @@ class ChangesetStatusModel(BaseModel): if cur_statuses: for st in cur_statuses: st.version += 1 - self.sa.add(st) + Session().add(st) def _create_status(user, repo, status, comment, revision, pull_request): new_status = ChangesetStatus() @@ -215,7 +213,7 @@ class ChangesetStatusModel(BaseModel): new_status = _create_status( user=user, repo=repo, status=status, comment=comment, revision=revision, pull_request=pull_request) - self.sa.add(new_status) + Session().add(new_status) return new_status elif pull_request: # pull request can have more than one revision associated to it @@ -227,7 +225,7 @@ class ChangesetStatusModel(BaseModel): user=user, repo=repo, status=status, comment=comment, revision=rev, pull_request=pull_request) new_statuses.append(new_status) - self.sa.add(new_status) + Session().add(new_status) return new_statuses def reviewers_statuses(self, pull_request): diff --git a/rhodecode/model/comment.py b/rhodecode/model/comment.py --- a/rhodecode/model/comment.py +++ b/rhodecode/model/comment.py @@ -432,7 +432,8 @@ class CommentsModel(BaseModel): pull_request_id=pull_request.pull_request_id, _anchor='comment-%s' % comment.comment_id) else: - return request.route_url('pullrequest_show', + return request.route_url( + 'pullrequest_show', repo_name=safe_str(pull_request.target_repo.repo_name), pull_request_id=pull_request.pull_request_id, _anchor='comment-%s' % comment.comment_id)