Skip to content

Adding eachBatch so project exporter can iterate through records

Max Fan requested to merge 421138_include_each_batch_to_export_relations into master

What does this MR do and why?

Currently bulk_import exporting of badges and uploads is broken if param[:batched] is set to true while exporting https://docs.gitlab.com/ee/api/group_relations_export.html#schedule-new-export

This fixes export of those relations

Relates to: #421138 (closed)

Screenshots or screen recordings

Screenshots are required for UI changes, and strongly recommended for all other merge requests.

Before After
[
    {
        "relation": "badges",
        "status": -1,
        "error": "undefined method `each_batch' for #<ActiveRecord::Associations::CollectionProxy [#<GroupBadge id: 143, link_url: \"http://gdk.test:3000/groups/goodgroup/-/edit\", image_url: \"http://gdk.test:3000/groups/goodgroup/-/edit\", project_id: nil, group_id: 302, ...",
        "updated_at": "2023-10-05T20:40:20.169Z",
        "batched": true,
        "batches_count": 1,
        "total_objects_count": 1,
        "batches": []
    },
[
    {
        "relation": "badges",
        "status": 1,
        "error": null,
        "updated_at": "2023-10-05T20:46:43.143Z",
        "batched": true,
        "batches_count": 2,
        "total_objects_count": 3,
        "batches": [
            {
                "status": 1,
                "batch_number": 1,
                "objects_count": 2,
                "error": null,
                "updated_at": "2023-10-05T20:46:43.046Z"
            },
            {
                "status": 1,
                "batch_number": 2,
                "objects_count": 1,
                "error": null,
                "updated_at": "2023-10-05T20:46:43.048Z"
            }
        ]
    },

How to set up and validate locally

  1. Trigger POST http://172.16.123.1:3000/api/v4/groups/298/export_relations?batched=true for a group you have locally
  2. Trigger GET http://172.16.123.1:3000/api/v4/groups/298/export_relations/status
  3. The above should return an error for badges
  4. Clone this branch & repeat steps 1 and 2
  5. Badges should successfully export like the screenshot above

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Max Fan

Merge request reports