Azure / Azure/azure-functions-host
Cosmos Input Binding OFFSET parameter improperly passed to host
- Dominant language
- C#
- Stars
- 2k
- Forks
- 483
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 36
Description
#### Investigative information
This was done via local development, if needed, I can deploy and reproduce. When a parameter is passed to the `sqlQuery` for a Cosmos input binding on the OFFSET clause, it improperly parses and throws an exception.
- Timestamp:
- Function App version (1.0 or 2.0): `2.0`
- Function App name:
- Function name(s) (as appropriate):
- Invocation ID:
- Region:
#### Repro steps
1. Create HTTP Trigger Function w/ Cosmos Input Binding
2. Adjust the `function.json` to with the follow bindings and associated settings for a `httpTrigger Function`; the same behavior occurs when the Cosmos Input is used as an activity in a durable function.
```
"bindings": [
{
"authLevel": "function",
"name": "req",
"type": "httpTrigger",
"direction": "in",
"route": "orchestrators/start",
"methods": ["post"]
},
{
"sqlQuery": "SELECT * FROM c WHERE c.somefield = {field} OFFSET {offset} LIMIT 10",
"type": "cosmosDB",
"name": "document",
"direction": "in",
"databaseName": "%COSMOS_DATABASE%",
"collectionName": "%COSMOS_COLLECTION%",
"connectionStringSetting": "COSMOS_CONNECTION_STRING"
}
]
```
or with a binding having the `{offset}` as part of the route definition.
```
{
"authLevel": "function",
"name": "req",
"type": "httpTrigger",
"direction": "in",
"route": "orchestrators/start/{offset}",
"methods": ["post"]
},
```
#### Expected behavior
- Setting the trigger or durable activity,
- Make a call to invoke the function/activity
- Input is parsed via the information from the post body, route, or input parameters to the function
- Performs the `sqlQuery` with the provided inputs
- Returns the appropriate data from cosmos
#### Actual behavior
- Once the function or durable activity is invoked, an error is thrown:
```
Stack: Error: Activity function 'HttpTrigger' failed: Message: {"errors":[{"severity":"Error","location":{"start":46,"end":53},"code":"SC2062","message":"The OFFSET count value exceeds the maximum allowed value."}]}
```
#### Known workarounds
Provide a description of any known workarounds.
- No Known Workarounds:
- Attempted to use a static value for the offset, but that only proves that the OFFSET/LIMIT clause is usable, not that it's useful.
- wrapped `{offset}` with `%` like with other variables with no success
#### Related information
Provide any related information
* Programming language used: Nodejs/Javascript
* Links to source: https://github.com/antempus/azure-function-recipe
* Bindings used HTTP, CosmosDB Input
-->
Contributor guide
Research direction
Begin with the function.json HTTP trigger and CosmosDB input binding described in the reproduction steps, then reproduce the sqlQuery using {offset} from the route or input parameters. Done means the provided offset is accepted for OFFSET and LIMIT 10 executes without the SC2062 error while returning the expected Cosmos data.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- azure, javascript, nodejs
- Domain
- backend, cloud, databases
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100