Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Binding Data for integers is inconsistent. #377

Closed
brendandburns opened this issue Mar 5, 2021 · 3 comments
Closed

Binding Data for integers is inconsistent. #377

brendandburns opened this issue Mar 5, 2021 · 3 comments

Comments

@brendandburns
Copy link
Member

Investigative information

Please provide the following:
N/A - this issue is reproducible locally.

Repro steps

Provide the steps required to reproduce the problem:

Run the following Typescript function:

import { AzureFunction, Context, HttpRequest } from "@azure/functions"

const httpTrigger: AzureFunction = async function (context: Context, req: HttpRequest): Promise<void> {
    context.res = {
        body:context.bindingData
    }
}

With the following function.json

{
  "bindings": [
    {
      "authLevel": "anonymous",
      "type": "httpTrigger",
      "direction": "in",
      "name": "req",
      "route": "periods/{id}",
      "methods": [
        "get"
      ]
    },
    {
      "type": "http",
      "direction": "out",
      "name": "res"
    }
  ],
  "scriptFile": "../dist/TestFunc/index.js"
}

Run func start

Hit the URL with 0 as the parameter:

curl <function-url>/api/periods/0

Output is:

{
  "invocationId": <hash>,
  "id": {
    "string": "0",
    "data": "string"
  },
  ....
}

Hit the URL with 1 as the parameter

curl <function-url>/api/periods/1

Output is:

{
  "invocationId": <hash>,
  "id":  1
...
}

Expected behavior

Format should be the same no matter what value is passed in.

Actual behavior

Format is integer literal for non-zero values (id: 1) and an object ({ ... }) for zero values.

Known workarounds

You can detect and respond in code, but that is ugly.

Related information

Provide any related information

  • Programming language used: Typescript
  • Links to source: Above
  • Bindings used: Above
Source
import { AzureFunction, Context, HttpRequest } from "@azure/functions"

const httpTrigger: AzureFunction = async function (context: Context, req: HttpRequest): Promise<void> {
    context.res = {
        body:context.bindingData
    }
}
@anthonychu
Copy link
Member

Thanks @brendandburns. This is an interesting behavior and we'll investigate.

We recommend that you use req.params to access routing parameters. The behavior should be consistent in that case.

@mhoeger
Copy link
Contributor

mhoeger commented Mar 30, 2021

I'm not sure where exactly something is going wrong, but it seems very likely that in some code path, we aren't explicitly checking for value == null. Related: #364

This is a breaking change we need to make with V4.

@ejizba
Copy link
Contributor

ejizba commented Jan 28, 2022

Fixed in #414

@ejizba ejizba closed this as completed Jan 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants