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

[BUG] Empty query params are discarded #894

Closed
nathanhi opened this issue Sep 29, 2021 · 4 comments
Closed

[BUG] Empty query params are discarded #894

nathanhi opened this issue Sep 29, 2021 · 4 comments

Comments

@nathanhi
Copy link

Investigative information

  • Timestamp: 1632902318
  • Function App name:
  • Function name(s) (as appropriate):
  • Core Tools version: 3.2.0-0 Commit hash: 5ffe001695be89a9b33cb569c875aef15938830b

Repro steps

Provide the steps required to reproduce the problem:
  1. Create simple function:
    __init__.py
    import azure.functions
    
    def main(req: azure.functions.HttpRequest):
        return str(req.params)
    function.json
    {
        "scriptFile": "__init__.py",
        "bindings": [
            {
                "authLevel": "anonymous",
                "type": "httpTrigger",
                "direction": "in",
                "name": "req",
                "methods": [
                    "get",
                    "post"
                ]
            },
            {
                "type": "http",
                "direction": "out",
                "name": "$return"
            }
        ]
    }
  2. Access function URL with query params ?paramwithvalue=foo&paramwithoutvalue
  3. {"paramwithvalue": "foo"} is returned

Expected behavior

I would expect the HttpRequest.params to contain all query params, defaulting to either a value of None or an empty string:

{
    "paramwithvalue": "foo",
    "paramwithoutvalue": ""
}

Actual behavior

The query parameter is silently discarded:

{
    "paramwithvalue": "foo"
}

Known workarounds

The query param can be retrieved via urllib.parse.parse_qs from the HttpRequest.urlobject:

__init__.py

from urllib.parse import parse_qs, urlparse

import azure.functions

def main(req: azure.functions.HttpRequest):
    return str(parse_qs(urlparse(req.url).query, keep_blank_values=True))

This will return the full set of params:

"{'paramwithvalue': ['foo'], 'paramwithoutvalue': ['']}"

Contents of the requirements.txt file:

azure-functions==1.7.2

Related information

This seems to be an underlying issue in the protobuf implementation and was already fixed in Azure/azure-functions-language-worker-protobuf#49

@shreyabatra4
Copy link
Contributor

Hi @nathanhi, are you still facing this issue?

@ghost
Copy link

ghost commented Feb 12, 2022

This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment.

@ghost ghost closed this as completed Feb 15, 2022
@lucyzhang929
Copy link
Contributor

Hello, I am still seeing this issue. Are there plans to fix this? There is a fix using UseNullableValueDictionaryForHttp mentioned in the PowerShell worker regarding the same issue Azure/azure-functions-powershell-worker#895.

@ghost
Copy link

ghost commented Jan 8, 2023

This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment.

This issue was closed.
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

3 participants