Inconsistent reponses in merge request API
Everyone can contribute. Help move this issue forward while earning points, leveling up and collecting rewards.
Summary
API requests to the /projects/:id/merge_requests endpoint return results with different fields depending on whether a specific MR is queried by IID or whether filtering is performed across multiple MRs. In a nutshell, I'd expect the following API calls to return the same result:
glab api "/projects/:id/merge_requests/4"
glab api "/projects/:id/merge_requests" -X GET -F "iids[]=4"
Steps to reproduce
- Select a project you'd like to verify this bug on with at least one merge request and note down its' ID (Go to the projects main page, click on the dot-menu in the top-right)
- Select a merge request you'd like to query and note down its' IID (the one you see in the UI)
- Open a shell of your choice and store the information in a variable:
export pid="<insert-project-id-here>" export mrid="<insert-merge-request-iid-here>" - Send a query like this:
curl -X GET "https://gitlab.com/api/v4/projects/$pid/merge_requests/$mrid" > detailed - Send another query like this:
curl -X GET "https://gitlab.com/api/v4/projects/$pid/merge_requests?iids[]=$mrid" > sparse - Compare the results using
jqanddiff
Example Project
You can pick any one you want, for the sake of having one I'll take this very repo right here. For demonstration purposes I arbitrarily picked MR 186223, but it doesn't matter really. Given the steps from above, fill in:
export pid="278964"
export mrid="186223"
What is the current bug behavior?
The detailed output has the following fields missing from sparse:
- subscribed
- changes_count
- latest_build_started_at
- latest_build_finished_at
- first_deployed_to_production_at
- pipeline
- head_pipeline
- diff_refs
- merge-error
- first_contribution
- user
What is the expected correct behavior?
Both responses should yield the same result.
Alternatively the API docs should mention more explicitly how/why these responses deviate.
I'm clearly in favor of the former as the latter will require a second API query to go from e.g. source branch name to fully detailed merge request information. Unless of course I'm missing something obvious, please let me know.
Relevant logs and/or screenshots
detailed output
{
"id": 372643932,
"iid": 186223,
"project_id": 278964,
"title": "Draft: Add topics filter to ciCatalogResources resolver",
"description": "## What does this MR do and why?\n\nThis change adds the ability to filter catalog resources by project topics. The update introduces a new GraphQL argument called \"topics\" that accepts an array of strings, allowing users to filter resources based on project topic names. The implementation includes adding the new argument to the resolver, extending the resources method in the listing class to handle topic filtering, and creating a new scope in the Resource model that joins with project topics to filter resources accordingly. The GraphQL API documentation has also been updated to reflect this new filtering option.\n\n## References\n\nhttps://gitlab.com/gitlab-org/gitlab/-/work_items/511291\n\n## Screenshots or screen recordings\n\n\n\n## How to set up and validate locally\n\nTBD\n\n## MR acceptance checklist\n\nEvaluate this MR against the [MR acceptance checklist](https://docs.gitlab.com/development/code_review/#acceptance-checklist).\nIt helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.\n\n\nRelated to #511291",
"state": "opened",
"created_at": "2025-03-28T07:18:32.240Z",
"updated_at": "2025-03-28T07:24:29.840Z",
"merged_by": null,
"merge_user": null,
"merged_at": null,
"closed_by": null,
"closed_at": null,
"target_branch": "master",
"source_branch": "511291-catalog-filter-on-topics",
"user_notes_count": 2,
"upvotes": 0,
"downvotes": 0,
"author": {
"id": 8198564,
"username": "rkadam3",
"name": "Rajendra Kadam",
"state": "active",
"locked": false,
"avatar_url": "https://gitlab.com/uploads/-/system/user/avatar/8198564/avatar.png",
"web_url": "https://gitlab.com/rkadam3"
},
"assignees": [
{
"id": 8198564,
"username": "rkadam3",
"name": "Rajendra Kadam",
"state": "active",
"locked": false,
"avatar_url": "https://gitlab.com/uploads/-/system/user/avatar/8198564/avatar.png",
"web_url": "https://gitlab.com/rkadam3"
}
],
"assignee": {
"id": 8198564,
"username": "rkadam3",
"name": "Rajendra Kadam",
"state": "active",
"locked": false,
"avatar_url": "https://gitlab.com/uploads/-/system/user/avatar/8198564/avatar.png",
"web_url": "https://gitlab.com/rkadam3"
},
"reviewers": [],
"source_project_id": 278964,
"target_project_id": 278964,
"labels": [
"backend",
"database::review pending",
"devops::verify",
"documentation",
"group::pipeline authoring",
"pipeline::tier-1",
"section::ci"
],
"draft": true,
"imported": false,
"imported_from": "none",
"work_in_progress": true,
"milestone": {
"id": 4599726,
"iid": 110,
"group_id": 9970,
"title": "17.11",
"description": "",
"state": "active",
"created_at": "2024-05-24T19:20:15.085Z",
"updated_at": "2024-05-24T19:20:15.085Z",
"due_date": "2025-04-11",
"start_date": "2025-03-15",
"expired": false,
"web_url": "https://gitlab.com/groups/gitlab-org/-/milestones/110"
},
"merge_when_pipeline_succeeds": false,
"merge_status": "can_be_merged",
"detailed_merge_status": "not_approved",
"merge_after": null,
"sha": "dc39fe377549644641b6005bfacfd61bf9c5d699",
"merge_commit_sha": null,
"squash_commit_sha": null,
"discussion_locked": null,
"should_remove_source_branch": null,
"force_remove_source_branch": true,
"prepared_at": "2025-03-28T07:19:21.789Z",
"reference": "!186223",
"references": {
"short": "!186223",
"relative": "!186223",
"full": "gitlab-org/gitlab!186223"
},
"web_url": "https://gitlab.com/gitlab-org/gitlab/-/merge_requests/186223",
"time_stats": {
"time_estimate": 0,
"total_time_spent": 0,
"human_time_estimate": null,
"human_total_time_spent": null
},
"squash": true,
"squash_on_merge": true,
"task_completion_status": {
"count": 0,
"completed_count": 0
},
"has_conflicts": false,
"blocking_discussions_resolved": false,
"approvals_before_merge": null,
"subscribed": false,
"changes_count": "4",
"latest_build_started_at": "2025-03-28T07:19:10.292Z",
"latest_build_finished_at": "2025-03-28T07:44:52.026Z",
"first_deployed_to_production_at": null,
"pipeline": {
"id": 1739680992,
"iid": 3976034,
"project_id": 278964,
"sha": "de609849445f88fddeddc70ba510f45a234b15f1",
"ref": "refs/merge-requests/186223/merge",
"status": "success",
"source": "merge_request_event",
"created_at": "2025-03-28T07:19:00.136Z",
"updated_at": "2025-03-28T07:44:52.037Z",
"web_url": "https://gitlab.com/gitlab-org/gitlab/-/pipelines/1739680992"
},
"head_pipeline": {
"id": 1739680992,
"iid": 3976034,
"project_id": 278964,
"sha": "de609849445f88fddeddc70ba510f45a234b15f1",
"ref": "refs/merge-requests/186223/merge",
"status": "success",
"source": "merge_request_event",
"created_at": "2025-03-28T07:19:00.136Z",
"updated_at": "2025-03-28T07:44:52.037Z",
"web_url": "https://gitlab.com/gitlab-org/gitlab/-/pipelines/1739680992",
"before_sha": "de609849445f88fddeddc70ba510f45a234b15f1",
"tag": false,
"yaml_errors": null,
"user": {
"id": 8198564,
"username": "rkadam3",
"name": "Rajendra Kadam",
"state": "active",
"locked": false,
"avatar_url": "https://gitlab.com/uploads/-/system/user/avatar/8198564/avatar.png",
"web_url": "https://gitlab.com/rkadam3"
},
"started_at": "2025-03-28T07:19:10.292Z",
"finished_at": "2025-03-28T07:44:52.026Z",
"committed_at": null,
"duration": 1532,
"queued_duration": 10,
"coverage": null,
"detailed_status": {
"icon": "status_success",
"text": "Passed",
"label": "passed",
"group": "success",
"tooltip": "passed",
"has_details": true,
"details_path": "/gitlab-org/gitlab/-/pipelines/1739680992",
"illustration": null,
"favicon": "/assets/ci_favicons/favicon_status_success-8451333011eee8ce9f2ab25dc487fe24a8758c694827a582f17f42b0a90446a2.png"
}
},
"diff_refs": {
"base_sha": "cdd5146a8f1c357847d6298e47f5d522e3b58e1f",
"head_sha": "dc39fe377549644641b6005bfacfd61bf9c5d699",
"start_sha": "b03fc139c300be3dea98aa686456bd248701ce1c"
},
"merge_error": null,
"first_contribution": false,
"user": {
"can_merge": false
}
}
sparse output
{
"id": 372643932,
"iid": 186223,
"project_id": 278964,
"title": "Draft: Add topics filter to ciCatalogResources resolver",
"description": "## What does this MR do and why?\n\nThis change adds the ability to filter catalog resources by project topics. The update introduces a new GraphQL argument called \"topics\" that accepts an array of strings, allowing users to filter resources based on project topic names. The implementation includes adding the new argument to the resolver, extending the resources method in the listing class to handle topic filtering, and creating a new scope in the Resource model that joins with project topics to filter resources accordingly. The GraphQL API documentation has also been updated to reflect this new filtering option.\n\n## References\n\nhttps://gitlab.com/gitlab-org/gitlab/-/work_items/511291\n\n## Screenshots or screen recordings\n\n\n\n## How to set up and validate locally\n\nTBD\n\n## MR acceptance checklist\n\nEvaluate this MR against the [MR acceptance checklist](https://docs.gitlab.com/development/code_review/#acceptance-checklist).\nIt helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.\n\n\nRelated to #511291",
"state": "opened",
"created_at": "2025-03-28T07:18:32.240Z",
"updated_at": "2025-03-28T07:24:29.840Z",
"merged_by": null,
"merge_user": null,
"merged_at": null,
"closed_by": null,
"closed_at": null,
"target_branch": "master",
"source_branch": "511291-catalog-filter-on-topics",
"user_notes_count": 2,
"upvotes": 0,
"downvotes": 0,
"author": {
"id": 8198564,
"username": "rkadam3",
"name": "Rajendra Kadam",
"state": "active",
"locked": false,
"avatar_url": "https://gitlab.com/uploads/-/system/user/avatar/8198564/avatar.png",
"web_url": "https://gitlab.com/rkadam3"
},
"assignees": [
{
"id": 8198564,
"username": "rkadam3",
"name": "Rajendra Kadam",
"state": "active",
"locked": false,
"avatar_url": "https://gitlab.com/uploads/-/system/user/avatar/8198564/avatar.png",
"web_url": "https://gitlab.com/rkadam3"
}
],
"assignee": {
"id": 8198564,
"username": "rkadam3",
"name": "Rajendra Kadam",
"state": "active",
"locked": false,
"avatar_url": "https://gitlab.com/uploads/-/system/user/avatar/8198564/avatar.png",
"web_url": "https://gitlab.com/rkadam3"
},
"reviewers": [],
"source_project_id": 278964,
"target_project_id": 278964,
"labels": [
"backend",
"database::review pending",
"devops::verify",
"documentation",
"group::pipeline authoring",
"pipeline::tier-1",
"section::ci"
],
"draft": true,
"imported": false,
"imported_from": "none",
"work_in_progress": true,
"milestone": {
"id": 4599726,
"iid": 110,
"group_id": 9970,
"title": "17.11",
"description": "",
"state": "active",
"created_at": "2024-05-24T19:20:15.085Z",
"updated_at": "2024-05-24T19:20:15.085Z",
"due_date": "2025-04-11",
"start_date": "2025-03-15",
"expired": false,
"web_url": "https://gitlab.com/groups/gitlab-org/-/milestones/110"
},
"merge_when_pipeline_succeeds": false,
"merge_status": "can_be_merged",
"detailed_merge_status": "not_approved",
"merge_after": null,
"sha": "dc39fe377549644641b6005bfacfd61bf9c5d699",
"merge_commit_sha": null,
"squash_commit_sha": null,
"discussion_locked": null,
"should_remove_source_branch": null,
"force_remove_source_branch": true,
"prepared_at": "2025-03-28T07:19:21.789Z",
"reference": "!186223",
"references": {
"short": "!186223",
"relative": "!186223",
"full": "gitlab-org/gitlab!186223"
},
"web_url": "https://gitlab.com/gitlab-org/gitlab/-/merge_requests/186223",
"time_stats": {
"time_estimate": 0,
"total_time_spent": 0,
"human_time_estimate": null,
"human_total_time_spent": null
},
"squash": true,
"squash_on_merge": true,
"task_completion_status": {
"count": 0,
"completed_count": 0
},
"has_conflicts": false,
"blocking_discussions_resolved": false,
"approvals_before_merge": null
}
And here is the resulting diff:
API response diff (sparse vs. detailed)
111c111,179
< "approvals_before_merge": null
---
> "approvals_before_merge": null,
> "subscribed": false,
> "changes_count": "4",
> "latest_build_started_at": "2025-03-28T07:19:10.292Z",
> "latest_build_finished_at": "2025-03-28T07:44:52.026Z",
> "first_deployed_to_production_at": null,
> "pipeline": {
> "id": 1739680992,
> "iid": 3976034,
> "project_id": 278964,
> "sha": "de609849445f88fddeddc70ba510f45a234b15f1",
> "ref": "refs/merge-requests/186223/merge",
> "status": "success",
> "source": "merge_request_event",
> "created_at": "2025-03-28T07:19:00.136Z",
> "updated_at": "2025-03-28T07:44:52.037Z",
> "web_url": "https://gitlab.com/gitlab-org/gitlab/-/pipelines/1739680992"
> },
> "head_pipeline": {
> "id": 1739680992,
> "iid": 3976034,
> "project_id": 278964,
> "sha": "de609849445f88fddeddc70ba510f45a234b15f1",
> "ref": "refs/merge-requests/186223/merge",
> "status": "success",
> "source": "merge_request_event",
> "created_at": "2025-03-28T07:19:00.136Z",
> "updated_at": "2025-03-28T07:44:52.037Z",
> "web_url": "https://gitlab.com/gitlab-org/gitlab/-/pipelines/1739680992",
> "before_sha": "de609849445f88fddeddc70ba510f45a234b15f1",
> "tag": false,
> "yaml_errors": null,
> "user": {
> "id": 8198564,
> "username": "rkadam3",
> "name": "Rajendra Kadam",
> "state": "active",
> "locked": false,
> "avatar_url": "https://gitlab.com/uploads/-/system/user/avatar/8198564/avatar.png",
> "web_url": "https://gitlab.com/rkadam3"
> },
> "started_at": "2025-03-28T07:19:10.292Z",
> "finished_at": "2025-03-28T07:44:52.026Z",
> "committed_at": null,
> "duration": 1532,
> "queued_duration": 10,
> "coverage": null,
> "detailed_status": {
> "icon": "status_success",
> "text": "Passed",
> "label": "passed",
> "group": "success",
> "tooltip": "passed",
> "has_details": true,
> "details_path": "/gitlab-org/gitlab/-/pipelines/1739680992",
> "illustration": null,
> "favicon": "/assets/ci_favicons/favicon_status_success-8451333011eee8ce9f2ab25dc487fe24a8758c694827a582f17f42b0a90446a2.png"
> }
> },
> "diff_refs": {
> "base_sha": "cdd5146a8f1c357847d6298e47f5d522e3b58e1f",
> "head_sha": "dc39fe377549644641b6005bfacfd61bf9c5d699",
> "start_sha": "b03fc139c300be3dea98aa686456bd248701ce1c"
> },
> "merge_error": null,
> "first_contribution": false,
> "user": {
> "can_merge": false
> }
Output of checks
This bug happens on GitLab.com
Results of GitLab environment info
I'm afraid I can't give that information to you since it's your GitLab instance. :-)
Results of GitLab application Check
Same as above
Possible fixes
Unknown