Azure / Azure/azure-functions-nodejs-library
Queue message contents overwrite triggerMetadata properties
- Dominant language
- TypeScript
- Stars
- 70
- Forks
- 35
- Avg merge
- 4d 18h
- Merged PRs (30d)
- 6
Description
When using a storage queue trigger with a JSON payload in the queue message properties from the deserialized payload are overwriting properties of InvocationContext.triggerMetadata.
The [documentation](https://learn.microsoft.com/en-us/azure/azure-functions/functions-bindings-storage-queue-trigger?tabs=python-v2%2Cisolated-process%2Cnodejs-v4%2Cextensionv5&pivots=programming-language-typescript#message-metadata) defines the properties of triggerMetadata, but mentions nothing about the payload properties also being present so this appears to be undocumented behaviour.
More importantly it prevents accessing the metadata properties if there is a clash between the property names in the payload and metadata, and allows them to be overwritten with unexpected values.
### Reproducing
@azure/functions version: 4.16.2
Function:
```typescript
import { app } from '@azure/functions';
app.storageQueue('metadataOverwrite', {
queueName: 'some-queue-name',
connection: 'AzureWebJobsStorage',
handler: (payload, context) => {
context.log('payload id', (payload as any).id);
// should output message guid, but outputs payload id instead
context.log('queue message id', context.triggerMetadata?.id);
}
})
```
Queue message:
```json
{
"id": "testing-id",
"propertyA": "abc"
}
```
Expected output:
```
payload id testing-id
queue message id [some guid]
```
Actual output:
```
payload id testing-id
queue message id testing-id
```
Contributor guide
Research direction
Start by tracing the storage queue trigger path from app.storageQueue and the handler's context.triggerMetadata, focusing on how the metadata shown in the issue is assembled. Add regression coverage for a payload property that collides with metadata, then verify the payload id remains available while triggerMetadata.id retains the queue message GUID.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- azure, node.js, typescript
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 52/100