500 error when accessing merge request discussions for projects imported via direct transfer
Summary
[Internal reference ticket with stacktrace and logs] Users encounter 500 errors when trying to access merge request discussions for projects that were imported through direct transfer. The error occurs specifically when the system attempts to render label references in the discussion content.
The UI indicates the error Something went wrong while fetching comments. Please try again
During the direct transfer, there were errors such as:
Type Title Error Correlation ID
merge_requests, DiffNote RecordInvalid Resolved by can't be blank 01JYNT9QJQP2JDWSFNA503XYJM
Steps to reproduce
- This project was included in a group, imported from another GitLab instance through Direct Transfer.
- The customer then navigates to a merge request in the imported project
- Try to access the discussions tab or load discussions via AJAX call to
/discussions.json
What is the current bug behavior?
The request fails with a 500 Internal Server Error when trying to load merge request discussions.
What is the expected correct behavior?
Merge request discussions should load successfully without errors, displaying all comments and discussions properly.
Relevant logs and/or screenshots
API Endpoint: GET /group/project/-/merge_requests/123/discussions.json
Error: NoMethodError: undefined method 'namespace' for #<Group id:<Group_ID> @archive/team/ID>
Stack trace location:
lib/banzai/filter/label_reference_filter.rb:124config/routes.rb:343
Root Cause Analysis
The issue occurs in the LabelReferenceFilter class when it attempts to generate URLs for label references. Specifically:
- The
url_for_objectmethod inLabelReferenceFiltercalls routing helpers likeproject_issues_url - These routing helpers expect the parent object to be a
Projectwith anamespacemethod - However, during direct transfer imports, the context may include
Groupobjects (like archived groups with paths like@archive/team/5510) -
Groupobjects inherit fromNamespacebut don't have anamespacemethod, causing theNoMethodError
Problematic code location:
# lib/banzai/filter/label_reference_filter.rb:87
Gitlab::Routing.url_helpers.public_send(label_url_method, parent, label_name: label.name, only_path: context[:only_path])
When parent is a Group and label_url_method is :project_issues_url, the routing helper fails because it expects a project object.
Possible fixes
- Add type checking: Verify the parent object type before calling routing helpers
- Handle Group contexts: Implement proper URL generation for group labels or skip URL generation when inappropriate
- Fix import process: Ensure direct transfer imports properly establish project-namespace relationships
Environment
- GitLab version: 17.11.3
- Instance type: Self-Managed
- Import method: Direct transfer
- Affected feature: Merge request discussions, label reference filtering
Impact
- Users cannot access merge request discussions for imported projects
- Affects code review workflow for imported projects
- May impact other areas where label references are rendered