Azure / Azure/azure-functions-durable-js

Calling client.purgeInstanceHistoryBy without createdTimeFrom throws

Open
#644 0 comments 0 reactions 0 assignees View on GitHub
P2
Dominant language
TypeScript
Stars
142
Forks
66
Avg merge
3d 19h
Merged PRs (30d)
4

Description

**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](https://github.com/Azure/azure-webjobs-sdk-script/wiki/Sharing-Your-Function-App-name-privately) for more details.

**To Reproduce**
Steps to reproduce the behavior:

App code:
```typescript
// HTTP handler for PurgeOrchestrationHistory
const PurgeOrchestrationHistory: HttpHandler = async (req: HttpRequest, context: InvocationContext): Promise => {
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: https://github.com/Azure/azure-functions-durable-python/issues/560
The fix will probably be in the shim in the extension

Contributor guide

Open the contributing guide

Research direction

Start at the client.purgeInstanceHistoryBy entry point and reproduce the call with createdTimeFrom omitted, using the TypeScript and Durable Functions versions listed. Trace the request into the extension shim mentioned in the issue. Done means the purge accepts an omitted start time and purges from the earliest available time without throwing.

Written by the indexing model from the issue text.

Assessment

Tech stack
node.js, typescript
Domain
api, backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.