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

  1. This project was included in a group, imported from another GitLab instance through Direct Transfer.
  2. The customer then navigates to a merge request in the imported project
  3. 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:124
  • config/routes.rb:343

Root Cause Analysis

The issue occurs in the LabelReferenceFilter class when it attempts to generate URLs for label references. Specifically:

  1. The url_for_object method in LabelReferenceFilter calls routing helpers like project_issues_url
  2. These routing helpers expect the parent object to be a Project with a namespace method
  3. However, during direct transfer imports, the context may include Group objects (like archived groups with paths like @archive/team/5510)
  4. Group objects inherit from Namespace but don't have a namespace method, causing the NoMethodError

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

  1. Add type checking: Verify the parent object type before calling routing helpers
  2. Handle Group contexts: Implement proper URL generation for group labels or skip URL generation when inappropriate
  3. 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
Edited by 🤖 GitLab Bot 🤖