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] queue_output might generate several messages from 1 string. #1492

Open
olsgaard opened this issue May 8, 2024 · 2 comments
Open

[BUG] queue_output might generate several messages from 1 string. #1492

olsgaard opened this issue May 8, 2024 · 2 comments
Assignees

Comments

@olsgaard
Copy link

olsgaard commented May 8, 2024

When using Queue Output Binding, sending a string as a queue message might result in several different queue messages. This does not align with the documentation[1], nor developer expectation.

For example, the documentation states that the following function will "set an individual message on the queue"

import azure.functions as func

def main(req: func.HttpRequest, msg: func.Out[str]) -> func.HttpResponse:
    input_msg = req.params.get('message')
    msg.set(input_msg)
    return 'OK'

However, if the message contains a string that looks like a json array, this will post multiple messages to the queue.

Version

Python version 3.10.14 (python3).
Azure Functions Core Tools
Core Tools Version: 4.0.5611 Commit hash: N/A +591b8aec842e333a87ea9e23ba390bb5effe0655 (64-bit)
Function Runtime Version: 4.31.1.22191

Repro steps

Provide the steps required to reproduce the problem:

Create a V2 Python Function app and include the following functions:

@app.queue_output(arg_name="$return", queue_name="start-queue", connection="AzureWebJobsStorage", data_type='BINARY')
@app.schedule(schedule="30 * * * * *", arg_name="myTimer", run_on_startup=True, use_monitor=False)
def timer_trigger(myTimer: func.TimerRequest) -> str:
    output = '[1,2,3,4,5]'
    return output

@app.queue_trigger(arg_name="msg", queue_name="start-queue", connection="AzureWebJobsStorage")
def queue_trigger(msg: func.QueueMessage):
    payload = msg.get_json()
    logging.info(f"Python Queue trigger processed a message: {payload} of type {type(payload)}")

Expected behavior

Provide a description of the expected behavior.

We expect 1 message is sent to queue when timer_trigger is executed, which results in 1 invocation of queue_trigger

[2024-05-08T06:53:30.929Z] Python Queue trigger processed a message: [1, 2, 3, 4, 5] of type <class 'list'>
[2024-05-08T06:53:30.931Z] Executed 'Functions.queue_trigger' (Succeeded, Id=1d1e3129-7a56-4168-841d-32ab050b032b, Duration=31ms)

Actual behavior

Provide a description of the actual behavior observed.

5 messages are sent to queue and 5 invocations of queue_trigger, each receiving a single number.

[2024-05-08T06:51:31.369Z] Python Queue trigger processed a message: 1 of type <class 'int'>
[2024-05-08T06:51:31.370Z] Executed 'Functions.queue_trigger' (Succeeded, Id=66d11682-2e8f-4f1d-8893-17765d51c3fe, Duration=15ms)
[2024-05-08T06:51:31.378Z] Python Queue trigger processed a message: 2 of type <class 'int'>
[2024-05-08T06:51:31.379Z] Python Queue trigger processed a message: 3 of type <class 'int'>
[2024-05-08T06:51:31.379Z] Executed 'Functions.queue_trigger' (Succeeded, Id=acd0b0da-de60-4244-b9a2-70aabcc4876d, Duration=24ms)
[2024-05-08T06:51:31.380Z] Executed 'Functions.queue_trigger' (Succeeded, Id=41af8b4a-afe3-4c95-9b7a-1169e7821403, Duration=24ms)
[2024-05-08T06:51:31.382Z] Python Queue trigger processed a message: 4 of type <class 'int'>
[2024-05-08T06:51:31.382Z] Python Queue trigger processed a message: 5 of type <class 'int'>
[2024-05-08T06:51:31.383Z] Executed 'Functions.queue_trigger' (Succeeded, Id=036fec0f-b10b-49da-9f71-1d3534f5d249, Duration=26ms)
[2024-05-08T06:51:31.383Z] Executed 'Functions.queue_trigger' (Succeeded, Id=2076cc59-a4d5-458c-bb0f-e0e90112b372, Duration=27ms)

Note, that according to the documentation we should expect 5 messages if we return a list of 5 items in timer_trigger(), however, we send 1 and only 1 string.

Known work around

If we wrap the output in braces and return a list of length 1, we get the expected result. However, the documentation states that a single string will result in a single message, and following the principle of least surprise, this should be true.

Contents of the requirements.txt file:

Provide the requirements.txt file to help us find out module related issues.
azure-functions

Related information

Provide any related information

[1] https://learn.microsoft.com/en-us/azure/azure-functions/functions-bindings-storage-queue-output?tabs=python-v1%2Cisolated-process%2Cnodejs-v4%2Cextensionv5&pivots=programming-language-python

@bhagyshricompany bhagyshricompany self-assigned this May 10, 2024
@bhagyshricompany
Copy link

Thanks for reporting will check and update you.

@bhagyshricompany
Copy link

@gavin-aguiar pls comment and validate.

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

2 participants