Some merge request API fields (diff_refs, changes_count) empty after MR is created
Summary
For a MR fetched from the API, the MR's diff_refs attribute is None, just after the MR is created and then become available after few seconds.
This has been experienced on gitlab.com and has been discussed on the forum: https://forum.gitlab.com/t/diff-refs-empty-after-mr-is-created/78975
The API documentation does not state that behavior.
Steps to reproduce
- Open a MR
- Fetch the MR from the API (as soon as the MR is created (timing is important here))
On our production automation, we rely on the webhooks system and wait for MR created events before we query the API to fetch the MR data. Even after the event is received the diff_refs attribute might be empty.
What is the current bug behavior?
As soon as the MR is created the MR's diff_refs attribute is None and become available few seconds later.
What is the expected correct behavior?
As soon as the MR is created the MR's diff_refs attribute is an object with the expected attributes.
Relevant logs and/or screenshots
{…, ‘latest_build_finished_at’: None, ‘first_deployed_to_production_at’: None, ‘pipeline’: None, ‘head_pipeline’: None, ‘diff_refs’: None, ‘merge_error’: None, ‘first_contribution’: False, ‘user’: {‘can_merge’: True}}
Possible fixes
It seems that the behavior is random and the delay to wait before the diff_refs attribute to be available is random but from our recent experience it is around 1 and 5 seconds.
From our side we could fix our automation by keep fetching the MR until the diff_refs attribute is as expected (w/ expected fields).
Gitlab could ensure that the MR data is complete before sending the webhook event.