fix(#890): handle None parent in GitlabComment.add_reaction#995
fix(#890): handle None parent in GitlabComment.add_reaction#995fullsend-ai-coder[bot] wants to merge 1 commit into
Conversation
When add_reaction() catches a duplicate award emoji error (race condition), the recovery path accessed self._parent.project to look up the current user's username. If _parent was None (e.g. comment from get_comment()), this crashed with AttributeError: 'NoneType' object has no attribute 'project'. Guard the _parent access and fall back to the raw GitLab client (self._raw_comment.manager.gitlab.user.username) when _parent is None. Also pass parent=self in get_comment() for both GitlabIssue and GitlabPullRequest so comments constructed through ogr always have a parent reference. Closes #890
|
🤖 Finished Review · ✅ Success · Started 5:04 PM UTC · Completed 5:20 PM UTC |
|
Build succeeded. ✔️ pre-commit SUCCESS in 3m 21s |
ReviewFindingsLow
Labels: PR modifies ogr/services/gitlab/ exclusively — GitLab service bug fix |
| or self._parent.project | ||
| ).service.user.get_username() | ||
| else: | ||
| login = self._raw_comment.manager.gitlab.user.username |
There was a problem hiding this comment.
[low] edge-case
The fallback path self._raw_comment.manager.gitlab.user.username assumes Gitlab.auth() was called (populates gitlab.user). If gitlab.user is None (no token), this would raise AttributeError. This is a pre-existing issue — the _parent path has the same assumption — and reactions require authentication, making the scenario unlikely in practice.
| == "gitlab.gnome.org" | ||
| ) | ||
|
|
||
|
|
There was a problem hiding this comment.
[low] test-class-style
New TestGitlabCommentAddReaction uses a plain pytest-style class while existing TestGitlabService in the same file inherits from unittest.TestCase. Both styles exist in the broader test suite, so not a strict violation.
Summary
AttributeErrorcrash inGitlabComment.add_reaction()when_parentisNoneand a duplicate award emoji race condition is encountered_parentaccess in the exception handler and fall back to the raw GitLab client (self._raw_comment.manager.gitlab.user.username) to resolve the current userparent=selfinget_comment()for bothGitlabIssueandGitlabPullRequestso comments constructed through ogr always have a parent referenceRoot Cause
When multiple workers add the same emoji reaction concurrently, GitLab returns a
GitlabCreateError("Award Emoji Name has already been taken"). The recovery path inadd_reaction()tried to find the existing reaction by looking up the current user viaself._parent.project.service.user.get_username(). If_parentwasNone(comment constructed without a parent argument), this crashed withAttributeError: 'NoneType' object has no attribute 'project'.Changes
ogr/services/gitlab/comments.py: AddNoneguard onself._parentwith fallback to raw GitLab client for username lookupogr/services/gitlab/issue.py: Passparent=selfinget_comment()ogr/services/gitlab/pull_request.py: Passparent=selfinget_comment()tests/unit/test_gitlab.py: Add unit tests covering duplicate emoji handling with and without parent, plus success pathTesting
_parent=None(the crash scenario), duplicate emoji with_parentset, and normal success pathCloses #890
Post-script verification
agent/890-fix-add-reaction-none-parent)8a9787200dc24411e2e0294178c6def0cbb3bbef..HEAD)