Skip to content

[BUG] Inconsistent typing of Python Azure Function blob-bound parameter #740

@shwars

Description

@shwars

When input parameter of Azure Function that is bound to Blob is typed as bytes, the actual type is str.

Official documentation states that the parameter should be typed as InputStream. This is the default when no typing is specified. However, we can specify str type and get the string. If we specify the type of input variable as bytes, the actual type is also str, which makes using the raw binary data difficult.

Azure Functions in C# support many different types, which makes development much more convenient. It would be nice to have the same functionality in Python to be consistent.

Proposed solutions:

  • Allow to specify bytes as input type, fix incorrect typing and add this to documentation
  • Throw type error exception if typing is specified incorrectly

Investigative information

  • Core Tools version: 3.0.2852

Repro steps

Create the following http-triggered Azure Function:

Code
import logging
import azure.functions as func

def main(inblb: bytes , req: func.HttpRequest) -> func.HttpResponse:
    logging.info(f"Type of input object is {type(inblb)}")
    return func.HttpResponse(f"Type of input object is {type(inblb)}",status_code=200)

inblb is bound to Azure Blob Storage:

function.json
{
  "scriptFile": "__init__.py",
  "bindings": [
    {
      "authLevel": "function",
      "type": "httpTrigger",
      "direction": "in",
      "name": "req",
      "methods": [
        "get",
        "post"
      ]
    },
    {
      "type": "http",
      "direction": "out",
      "name": "$return"
    },
    {
      "type": "blob",
      "direction": "in",
      "name": "inblb",
      "path": "thecontainer/thefile",
      "connection": "demoazfuncstorage_STORAGE"
    }
  ]
}

Expected behavior

Either one of:

  • [suggested] Type of input object is bytes
  • Exception is thrown to indicate incorrect typing

Actual behavior

Type of input object is str

Known workarounds

Use func.InputStream as type of blob-bound parameter, and obtain the content of blob using read() method.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions