Skip to content

DeviceManagementExportJob does not finish. #1218

@cr-23

Description

@cr-23

Describe the bug

I'm having a problem with the DeviceManagementExportJob. For about a month now, the export jobs I run through the Microsoft Graph API often don't complete. Every now and then, the job works, but most of the time it just gets stuck and never finishes.

I'm using the SDK to fetch Intune data by starting an export job, waiting for it to complete, and then downloading the results. The code is set up to check every 10 seconds for the job status. I've checked the documentation and the logs but am unable to pinpoint the issue.

The application has the following Microsoft Graph permissions:

  • Device.Read.All
  • DeviceManagementApps.Read.All
  • Files.SelectedOperations.Selected (not related)

This is executed within a ContainerAppJob with a time limit of 10 minutes. I have attached the execution history, which shows both failures and successes.

I’m looking for advice on whether this is a known issue, if there are any best practices or configurations I should follow to fix this, or if it might be a problem with the Graph API itself.

Image

Image

Expected behavior

When I trigger an export job through the Microsoft Graph API, I expect the job to process and complete within about 5 minutes. Once it’s done, the status should show as "Completed," and I should be able to download the resulting zip file without any issues. This process should work reliably every time I run it.

How to reproduce

import asyncio
import logging
from msgraph import GraphServiceClient
from msgraph.generated.models.device_management_export_job import (
    DeviceManagementExportJob,
)
from msgraph.generated.models.device_management_report_file_format import (
    DeviceManagementReportFileFormat,
)
from msgraph.generated.models.device_management_report_status import (
    DeviceManagementReportStatus,
)
from azure.identity import ClientSecretCredential

# Configure logging
logging.basicConfig(
    level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s"
)

tenant_id = ""
client_id = ""
client_secret = ""


async def post_export_job(graph_client):
    logging.debug("Starting export job creation.")
    request_body = DeviceManagementExportJob(
        report_name="AppInvRawData",
        format=DeviceManagementReportFileFormat.Csv,
    )
    try:
        result = await graph_client.device_management.reports.export_jobs.post(
            request_body
        )
        logging.info("Export job created successfully: %s", result)
        return result
    except Exception as e:
        logging.error("Failed to create export job: %s", e)
        raise


async def get_export_job(graph_client, job_id):
    logging.debug("Polling export job status for job ID: %s", job_id)
    try:
        result = await graph_client.device_management.reports.export_jobs.by_device_management_export_job_id(
            job_id
        ).get()
        logging.info("Current export job status: %s", result.status)
        if result.status == DeviceManagementReportStatus.Completed:
            logging.info(
                "Export job completed successfully. Download URL: %s", result.url
            )
            return result
        await asyncio.sleep(10)
        return await get_export_job(graph_client, job_id)
    except Exception as e:
        logging.error("Error while polling export job status: %s", e)
        raise


async def main():
    logging.debug("Initializing Graph API client.")
    try:
        credentials = ClientSecretCredential(tenant_id, client_id, client_secret)
        graph_client = GraphServiceClient(
            credentials=credentials, scopes=["https://graph.microsoft.com/.default"]
        )
        # Start the export job and check its status
        create_report = await post_export_job(graph_client)
        job_id = create_report.id
        await get_export_job(graph_client, job_id)
        logging.info("Process completed successfully.")
    except Exception as e:
        logging.error("An error occurred in the main process: %s", e)
        raise


if __name__ == "__main__":
    asyncio.run(main())

### SDK Version

1.29.0

### Latest version known to work for scenario above?

1.17.0 ( just occasionally)

### Known Workarounds

_No response_

Debug output

Click to expand log 2025-05-12 13:54:06,604 - INFO - ClientSecretCredential.get_token succeeded 2025-05-12 13:54:06,945 - INFO - HTTP Request: POST https://graph.microsoft.com/v1.0/deviceManagement/reports/exportJobs "HTTP/2 201 Created" 2025-05-12 13:54:07,835 - INFO - Export job created successfully: DeviceManagementExportJob(additional_data={'@odata.context': 'https://graph.microsoft.com/v1.0/$metadata#deviceManagement/reports/exportJobs/$entity'}, id='AppInvRawData_fc7619a9-c81e-4607-80c9-979bda359c93', odata_type=None, expiration_date_time=datetime.datetime(1, 1, 1, 0, 0, tzinfo=datetime.timezone.utc), filter=None, format=, localization_type=, report_name='AppInvRawData', request_date_time=datetime.datetime(2025, 5, 12, 11, 54, 6, 391437, tzinfo=datetime.timezone.utc), select=[], snapshot_id=None, status=, url=None) 2025-05-12 13:54:07,835 - INFO - Polling export job status for job ID: AppInvRawData_fc7619a9-c81e-4607-80c9-979bda359c93 2025-05-12 13:54:07,837 - INFO - ClientSecretCredential.get_token succeeded 2025-05-12 13:54:07,922 - INFO - HTTP Request: GET https://graph.microsoft.com/v1.0/deviceManagement/reports/exportJobs/AppInvRawData_fc7619a9-c81e-4607-80c9-979bda359c93 "HTTP/2 200 OK" 2025-05-12 13:54:07,928 - INFO - Current export job status: DeviceManagementReportStatus.InProgress 2025-05-12 13:54:17,370 - INFO - Polling export job status for job ID: AppInvRawData_fc7619a9-c81e-4607-80c9-979bda359c93 2025-05-12 13:54:17,371 - INFO - ClientSecretCredential.get_token succeeded 2025-05-12 13:54:17,540 - INFO - HTTP Request: GET https://graph.microsoft.com/v1.0/deviceManagement/reports/exportJobs/AppInvRawData_fc7619a9-c81e-4607-80c9-979bda359c93 "HTTP/2 200 OK" 2025-05-12 13:54:17,547 - INFO - Current export job status: DeviceManagementReportStatus.InProgress 2025-05-12 13:54:27,640 - INFO - Polling export job status for job ID: AppInvRawData_fc7619a9-c81e-4607-80c9-979bda359c93 2025-05-12 13:54:27,642 - INFO - ClientSecretCredential.get_token succeeded 2025-05-12 13:54:27,860 - INFO - HTTP Request: GET https://graph.microsoft.com/v1.0/deviceManagement/reports/exportJobs/AppInvRawData_fc7619a9-c81e-4607-80c9-979bda359c93 "HTTP/2 200 OK" 2025-05-12 13:54:27,864 - INFO - Current export job status: DeviceManagementReportStatus.InProgress 2025-05-12 13:54:37,894 - INFO - Polling export job status for job ID: AppInvRawData_fc7619a9-c81e-4607-80c9-979bda359c93 2025-05-12 13:54:37,894 - INFO - ClientSecretCredential.get_token succeeded 2025-05-12 13:54:38,796 - INFO - HTTP Request: GET https://graph.microsoft.com/v1.0/deviceManagement/reports/exportJobs/AppInvRawData_fc7619a9-c81e-4607-80c9-979bda359c93 "HTTP/2 200 OK" 2025-05-12 13:54:38,803 - INFO - Current export job status: DeviceManagementReportStatus.InProgress 2025-05-12 13:54:48,232 - INFO - Polling export job status for job ID: AppInvRawData_fc7619a9-c81e-4607-80c9-979bda359c93 2025-05-12 13:54:48,233 - INFO - ClientSecretCredential.get_token succeeded 2025-05-12 13:54:48,412 - INFO - HTTP Request: GET https://graph.microsoft.com/v1.0/deviceManagement/reports/exportJobs/AppInvRawData_fc7619a9-c81e-4607-80c9-979bda359c93 "HTTP/2 200 OK" 2025-05-12 13:54:48,418 - INFO - Current export job status: DeviceManagementReportStatus.InProgress 2025-05-12 13:54:58,443 - INFO - Polling export job status for job ID: AppInvRawData_fc7619a9-c81e-4607-80c9-979bda359c93 2025-05-12 13:54:58,444 - INFO - ClientSecretCredential.get_token succeeded 2025-05-12 13:54:58,675 - INFO - HTTP Request: GET https://graph.microsoft.com/v1.0/deviceManagement/reports/exportJobs/AppInvRawData_fc7619a9-c81e-4607-80c9-979bda359c93 "HTTP/2 200 OK" 2025-05-12 13:54:58,682 - INFO - Current export job status: DeviceManagementReportStatus.InProgress 2025-05-12 13:55:08,704 - INFO - Polling export job status for job ID: AppInvRawData_fc7619a9-c81e-4607-80c9-979bda359c93 2025-05-12 13:55:08,704 - INFO - ClientSecretCredential.get_token succeeded 2025-05-12 13:55:09,589 - INFO - HTTP Request: GET https://graph.microsoft.com/v1.0/deviceManagement/reports/exportJobs/AppInvRawData_fc7619a9-c81e-4607-80c9-979bda359c93 "HTTP/2 200 OK" 2025-05-12 13:55:09,595 - INFO - Current export job status: DeviceManagementReportStatus.InProgress 2025-05-12 13:55:19,003 - INFO - Polling export job status for job ID: AppInvRawData_fc7619a9-c81e-4607-80c9-979bda359c93 2025-05-12 13:55:19,004 - INFO - ClientSecretCredential.get_token succeeded 2025-05-12 13:55:19,176 - INFO - HTTP Request: GET https://graph.microsoft.com/v1.0/deviceManagement/reports/exportJobs/AppInvRawData_fc7619a9-c81e-4607-80c9-979bda359c93 "HTTP/2 200 OK" 2025-05-12 13:55:19,180 - INFO - Current export job status: DeviceManagementReportStatus.InProgress 2025-05-12 13:55:29,219 - INFO - Polling export job status for job ID: AppInvRawData_fc7619a9-c81e-4607-80c9-979bda359c93 2025-05-12 13:55:29,220 - INFO - ClientSecretCredential.get_token succeeded 2025-05-12 13:55:29,407 - INFO - HTTP Request: GET https://graph.microsoft.com/v1.0/deviceManagement/reports/exportJobs/AppInvRawData_fc7619a9-c81e-4607-80c9-979bda359c93 "HTTP/2 200 OK" 2025-05-12 13:55:29,410 - INFO - Current export job status: DeviceManagementReportStatus.InProgress 2025-05-12 13:55:39,430 - INFO - Polling export job status for job ID: AppInvRawData_fc7619a9-c81e-4607-80c9-979bda359c93 2025-05-12 13:55:39,431 - INFO - ClientSecretCredential.get_token succeeded 2025-05-12 13:55:39,617 - INFO - HTTP Request: GET https://graph.microsoft.com/v1.0/deviceManagement/reports/exportJobs/AppInvRawData_fc7619a9-c81e-4607-80c9-979bda359c93 "HTTP/2 200 OK" 2025-05-12 13:55:39,623 - INFO - Current export job status: DeviceManagementReportStatus.InProgress 2025-05-12 13:55:49,199 - INFO - Polling export job status for job ID: AppInvRawData_fc7619a9-c81e-4607-80c9-979bda359c93 2025-05-12 13:55:49,200 - INFO - ClientSecretCredential.get_token succeeded 2025-05-12 13:55:49,409 - INFO - HTTP Request: GET https://graph.microsoft.com/v1.0/deviceManagement/reports/exportJobs/AppInvRawData_fc7619a9-c81e-4607-80c9-979bda359c93 "HTTP/2 200 OK" 2025-05-12 13:55:49,412 - INFO - Current export job status: DeviceManagementReportStatus.InProgress 2025-05-12 13:55:59,463 - INFO - Polling export job status for job ID: AppInvRawData_fc7619a9-c81e-4607-80c9-979bda359c93 2025-05-12 13:55:59,465 - INFO - ClientSecretCredential.get_token succeeded 2025-05-12 13:55:59,638 - INFO - HTTP Request: GET https://graph.microsoft.com/v1.0/deviceManagement/reports/exportJobs/AppInvRawData_fc7619a9-c81e-4607-80c9-979bda359c93 "HTTP/2 200 OK" 2025-05-12 13:55:59,641 - INFO - Current export job status: DeviceManagementReportStatus.InProgress 2025-05-12 13:56:09,652 - INFO - Polling export job status for job ID: AppInvRawData_fc7619a9-c81e-4607-80c9-979bda359c93 2025-05-12 13:56:09,652 - INFO - ClientSecretCredential.get_token succeeded 2025-05-12 13:56:09,835 - INFO - HTTP Request: GET https://graph.microsoft.com/v1.0/deviceManagement/reports/exportJobs/AppInvRawData_fc7619a9-c81e-4607-80c9-979bda359c93 "HTTP/2 200 OK" 2025-05-12 13:56:09,840 - INFO - Current export job status: DeviceManagementReportStatus.InProgress 2025-05-12 13:56:19,346 - INFO - Polling export job status for job ID: AppInvRawData_fc7619a9-c81e-4607-80c9-979bda359c93 2025-05-12 13:56:19,347 - INFO - ClientSecretCredential.get_token succeeded 2025-05-12 13:56:19,547 - INFO - HTTP Request: GET https://graph.microsoft.com/v1.0/deviceManagement/reports/exportJobs/AppInvRawData_fc7619a9-c81e-4607-80c9-979bda359c93 "HTTP/2 200 OK" 2025-05-12 13:56:19,553 - INFO - Current export job status: DeviceManagementReportStatus.InProgress 2025-05-12 13:56:29,577 - INFO - Polling export job status for job ID: AppInvRawData_fc7619a9-c81e-4607-80c9-979bda359c93 2025-05-12 13:56:29,577 - INFO - ClientSecretCredential.get_token succeeded 2025-05-12 13:56:29,846 - INFO - HTTP Request: GET https://graph.microsoft.com/v1.0/deviceManagement/reports/exportJobs/AppInvRawData_fc7619a9-c81e-4607-80c9-979bda359c93 "HTTP/2 200 OK" 2025-05-12 13:56:29,850 - INFO - Current export job status: DeviceManagementReportStatus.InProgress 2025-05-12 13:56:39,867 - INFO - Polling export job status for job ID: AppInvRawData_fc7619a9-c81e-4607-80c9-979bda359c93 2025-05-12 13:56:39,868 - INFO - ClientSecretCredential.get_token succeeded 2025-05-12 13:56:40,042 - INFO - HTTP Request: GET https://graph.microsoft.com/v1.0/deviceManagement/reports/exportJobs/AppInvRawData_fc7619a9-c81e-4607-80c9-979bda359c93 "HTTP/2 200 OK" 2025-05-12 13:56:40,047 - INFO - Current export job status: DeviceManagementReportStatus.InProgress 2025-05-12 13:56:50,084 - INFO - Polling export job status for job ID: AppInvRawData_fc7619a9-c81e-4607-80c9-979bda359c93 2025-05-12 13:56:50,085 - INFO - ClientSecretCredential.get_token succeeded 2025-05-12 13:56:49,702 - INFO - HTTP Request: GET https://graph.microsoft.com/v1.0/deviceManagement/reports/exportJobs/AppInvRawData_fc7619a9-c81e-4607-80c9-979bda359c93 "HTTP/2 200 OK" 2025-05-12 13:56:49,709 - INFO - Current export job status: DeviceManagementReportStatus.InProgress 2025-05-12 13:56:59,742 - INFO - Polling export job status for job ID: AppInvRawData_fc7619a9-c81e-4607-80c9-979bda359c93 2025-05-12 13:56:59,742 - INFO - ClientSecretCredential.get_token succeeded 2025-05-12 13:56:59,923 - INFO - HTTP Request: GET https://graph.microsoft.com/v1.0/deviceManagement/reports/exportJobs/AppInvRawData_fc7619a9-c81e-4607-80c9-979bda359c93 "HTTP/2 200 OK" 2025-05-12 13:56:59,929 - INFO - Current export job status: DeviceManagementReportStatus.InProgress 2025-05-12 13:57:09,961 - INFO - Polling export job status for job ID: AppInvRawData_fc7619a9-c81e-4607-80c9-979bda359c93 2025-05-12 13:57:09,962 - INFO - ClientSecretCredential.get_token succeeded 2025-05-12 13:57:10,147 - INFO - HTTP Request: GET https://graph.microsoft.com/v1.0/deviceManagement/reports/exportJobs/AppInvRawData_fc7619a9-c81e-4607-80c9-979bda359c93 "HTTP/2 200 OK" 2025-05-12 13:57:10,157 - INFO - Current export job status: DeviceManagementReportStatus.InProgress 2025-05-12 13:57:20,218 - INFO - Polling export job status for job ID: AppInvRawData_fc7619a9-c81e-4607-80c9-979bda359c93 2025-05-12 13:57:20,219 - INFO - ClientSecretCredential.get_token succeeded 2025-05-12 13:57:20,397 - INFO - HTTP Request: GET https://graph.microsoft.com/v1.0/deviceManagement/reports/exportJobs/AppInvRawData_fc7619a9-c81e-4607-80c9-979bda359c93 "HTTP/2 200 OK" 2025-05-12 13:57:20,404 - INFO - Current export job status: DeviceManagementReportStatus.InProgress 2025-05-12 13:57:29,850 - INFO - Polling export job status for job ID: AppInvRawData_fc7619a9-c81e-4607-80c9-979bda359c93 2025-05-12 13:57:29,851 - INFO - ClientSecretCredential.get_token succeeded 2025-05-12 13:57:30,024 - INFO - HTTP Request: GET https://graph.microsoft.com/v1.0/deviceManagement/reports/exportJobs/AppInvRawData_fc7619a9-c81e-4607-80c9-979bda359c93 "HTTP/2 200 OK" 2025-05-12 13:57:30,029 - INFO - Current export job status: DeviceManagementReportStatus.InProgress
```

Configuration

OS: Linux (Running on WSL2)
Kernel: 5.15.167.4-microsoft-standard-WSL2
Distribution: Ubuntu 24.04.2 LTS (Noble Numbat)
Processor: x86_64
Python Version: 3.12.3

Other information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    status:waiting-for-triageAn issue that is yet to be reviewed or assignedtype:bugA broken experience

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions