Skip to content

Calling client.purgeInstanceHistoryBy without createdTimeFrom throws #644

@andystaples

Description

@andystaples

Describe the bug
Calling client.purgeInstanceHistoryBy without providing a value for createdTimeFrom throws an error
""Failed to purge all instance history: The operatio [...]"

Investigative information

  • Durable Functions extension version: 3.3.0
  • durable-functions npm module version: 3.1.0
  • Language (JavaScript/TypeScript) and version: TypeScript 4.9.5
  • Node.js version: v22.15.0

If deployed to Azure App Service

N/A

If you don't want to share your Function App name or Functions names on GitHub, please be sure to provide your Invocation ID, Timestamp, and Region - we can use this to look up your Function App/Function. Provide an invocation id per Function. See the Functions Host wiki for more details.

To Reproduce
Steps to reproduce the behavior:

App code:

// HTTP handler for PurgeOrchestrationHistory
const PurgeOrchestrationHistory: HttpHandler = async (req: HttpRequest, context: InvocationContext): Promise<HttpResponseInit> => {
    context.log('Starting purge all instance history');
    try {
        // Parse optional query parameters for purgeStartTime and purgeEndTime
        let purgeStartTime: Date | undefined = undefined;
        let purgeEndTime: Date | undefined = undefined;

        const purgeStartTimeParam = req.query.get('purgeStartTime');
        const purgeEndTimeParam = req.query.get('purgeEndTime');

        if (purgeStartTimeParam) {
            purgeStartTime = new Date(purgeStartTimeParam);
        }
        if (purgeEndTimeParam) {
            purgeEndTime = new Date(purgeEndTimeParam);
        }

        const client = df.getClient(context);

        // Purge orchestration history
        const result = await client.purgeInstanceHistoryBy({
            createdTimeFrom: purgeStartTime,
            createdTimeTo: purgeEndTime,
            runtimeStatus: [
                df.OrchestrationRuntimeStatus.Completed,
                df.OrchestrationRuntimeStatus.Failed,
                df.OrchestrationRuntimeStatus.Terminated
            ]
        });

        context.log('Finished purge all instance history');
        return {
            status: 200,
            body: `Purged ${result.instancesDeleted} records`,
            headers: { 'Content-Type': 'text/plain' }
        };
    } catch (ex: any) {
        context.error('Failed to purge all instance history', ex);
        return {
            status: 500,
            body: `Failed to purge all instance history: ${ex?.message ?? ex}`,
            headers: { 'Content-Type': 'text/plain' }
        };
    }
};

Query URL for Core Tools: http://localhost:7071/api/HelloCities_HttpStart_Scheduled

While not required, providing your orchestrator's source code in anonymized form is often very helpful when investigating unexpected orchestrator behavior.

Expected behavior
Without scheduledStartTime, the purge request should purge starting from "all time" or DateTime.MinValue in the Durable extension

Actual behavior
The method throws an exception

Screenshots
N/A

Known workarounds
Always provide scheduled start time in the functionapp code

Additional context

The same issue exists in Python: Azure/azure-functions-durable-python#560
The fix will probably be in the shim in the extension

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Priority 2 item

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions