Skip to content

Azure Functions Python Worker: ValueError parsing Service Bus enqueued_time_utc with milliseconds but no timezone offset #4359

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

Open
iddog opened this issue Apr 11, 2025 · 0 comments

Comments

@iddog
Copy link

iddog commented Apr 11, 2025

Version

  • Azure Functions Core Tools: v4.0.7030 - tried both npm and brew installers
  • Python Version: 3.11 (from stack trace)
  • azure-functions library version: 1.23.0
  • OS: macOS , potentially affects other platforms including Azure App Service.
  • Binding: Azure Service Bus Trigger

Description

The Azure Functions Python worker fails to process incoming Azure Service Bus messages if certain datetime metadata fields (specifically observed with enqueued_time_utc) are formatted as ISO 8601 strings containing milliseconds but lacking a timezone offset (e.g., YYYY-MM-DDTHH:MM:SS.sss).

This results in an unhandled ValueError during the message decoding phase within the worker's internal libraries, preventing the user's function code from executing for that message.

Exception has occurred: ValueError
time data '2025-04-11T01:10:50.251' does not match format '%Y-%m-%dT%H:%M:%S+00:00'
File "/Users/.../.nvm/versions/node/v22.11.0/lib/node_modules/azure-functions-core-tools/bin/workers/python/3.11/OSX/Arm64/azure/functions/_utils.py", line 36, in try_parse_datetime_with_formats
dt = datetime.strptime(datetime_str, fmt)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/iddog/.nvm/versions/node/v22.11.0/lib/node_modules/azure-functions-core-tools/bin/workers/python/3.11/OSX/Arm64/azure/functions/meta.py", line 291, in _parse_datetime_utc
dt, _, excpt = try_parse_datetime_with_formats(
File "/Users/iddog/.nvm/versions/node/v22.11.0/lib/node_modules/azure-functions-core-tools/bin/workers/python/3.11/OSX/Arm64/azure/functions/meta.py", line 231, in _parse_datetime
utc_time, utc_time_error = cls._parse_datetime_utc(datetime_str)
File "/Users/iddog/.nvm/versions/node/v22.11.0/lib/node_modules/azure-functions-core-tools/bin/workers/python/3.11/OSX/Arm64/azure/functions/meta.py", line 197, in _parse_datetime_metadata
return cls._parse_datetime(datetime_str)
File "/Users/iddog/.nvm/versions/node/v22.11.0/lib/node_modules/azure-functions-core-tools/bin/workers/python/3.11/OSX/Arm64/azure/functions/servicebus.py", line 312, in decode_single_message
enqueued_time_utc=cls._parse_datetime_metadata(
File "/Users/iddog/.nvm/versions/node/v22.11.0/lib/node_modules/azure-functions-core-tools/bin/workers/python/3.11/OSX/Arm64/azure/functions/servicebus.py", line 258, in decode
return cls.decode_single_message(
File "/Users/iddog/.nvm/versions/node/v22.11.0/lib/node_modules/azure-functions-core-tools/bin/workers/python/3.11/OSX/Arm64/azure_functions_worker/bindings/meta.py", line 190, in from_incoming_proto
return binding.decode(datum, trigger_metadata=metadata)
File "/Users/iddog/.nvm/versions/node/v22.11.0/lib/node_modules/azure-functions-core-tools/bin/workers/python/3.11/OSX/Arm64/azure_functions_worker/dispatcher.py", line 632, in _handle__invocation_request
args[pb.name] = bindings.from_incoming_proto(
File "/Users/iddog/.nvm/versions/node/v22.11.0/lib/node_modules/azure-functions-core-tools/bin/workers/python/3.11/OSX/Arm64/azure_functions_worker/dispatcher.py", line 296, in _dispatch_grpc_request
resp = await request_handler(request)
File "/Users/iddog/.nvm/versions/node/v22.11.0/lib/node_modules/azure-functions-core-tools/bin/workers/python/3.11/OSX/Arm64/azure_functions_worker/main.py", line 61, in main
return asyncio.run(start_async(
File "/Users/iddog/.nvm/versions/node/v22.11.0/lib/node_modules/azure-functions-core-tools/bin/workers/python/3.11/OSX/Arm64/worker.py", line 68, in
main.main()
ValueError: time data '2025-04-11T01:10:50.251' does not match format '%Y-%m-%dT%H:%M:%S+00:00'

Steps to reproduce

  1. Create an Azure Function with a Service Bus Trigger using the Python v2 programming model.
  2. Send a message to the corresponding Service Bus queue.
  3. Ensure that the message metadata generated or propagated by Service Bus includes a timestamp field (like enqueued_time_utc) with the format YYYY-MM-DDTHH:MM:SS.sss (e.g., 2025-04-11T00:27:53.569).
  4. Observe the Azure Functions runtime logs (either locally with Core Tools or potentially in Azure Application Insights).

Expected Behavior

The Azure Functions Python worker should robustly parse valid ISO 8601 timestamp formats present in Service Bus message metadata, including formats with milliseconds but no explicit timezone offset. The function trigger should successfully decode the message and invoke the user's function code.

Actual Behavior

The function execution fails before user code is invoked, with the following ValueError and stack trace:

Exception has occurred: ValueError
time data '2025-04-11T00:27:53.569' does not match format '%Y-%m-%dT%H:%M:%S+00:00'
  File "/opt/homebrew/Cellar/azure-functions-core-tools@4/4.0.7030/workers/python/3.11/OSX/Arm64/azure/functions/_utils.py", line 36, in try_parse_datetime_with_formats
    dt = datetime.strptime(datetime_str, fmt)
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/azure-functions-core-tools@4/4.0.7030/workers/python/3.11/OSX/Arm64/azure/functions/meta.py", line 291, in _parse_datetime_utc
    dt, _, excpt = try_parse_datetime_with_formats(
  File "/opt/homebrew/Cellar/azure-functions-core-tools@4/4.0.7030/workers/python/3.11/OSX/Arm64/azure/functions/meta.py", line 231, in _parse_datetime
    utc_time, utc_time_error = cls._parse_datetime_utc(datetime_str)
  File "/opt/homebrew/Cellar/azure-functions-core-tools@4/4.0.7030/workers/python/3.11/OSX/Arm64/azure/functions/meta.py", line 197, in _parse_datetime_metadata
    return cls._parse_datetime(datetime_str)
  File "/opt/homebrew/Cellar/azure-functions-core-tools@4/4.0.7030/workers/python/3.11/OSX/Arm64/azure/functions/servicebus.py", line 312, in decode_single_message
    enqueued_time_utc=cls._parse_datetime_metadata(
  File "/opt/homebrew/Cellar/azure-functions-core-tools@4/4.0.7030/workers/python/3.11/OSX/Arm64/azure/functions/servicebus.py", line 258, in decode
    return cls.decode_single_message(
  File "/opt/homebrew/Cellar/azure-functions-core-tools@4/4.0.7030/workers/python/3.11/OSX/Arm64/azure_functions_worker/bindings/meta.py", line 190, in from_incoming_proto
    return binding.decode(datum, trigger_metadata=metadata)
  File "/opt/homebrew/Cellar/azure-functions-core-tools@4/4.0.7030/workers/python/3.11/OSX/Arm64/azure_functions_worker/dispatcher.py", line 632, in _handle__invocation_request
    args[pb.name] = bindings.from_incoming_proto(
  File "/opt/homebrew/Cellar/azure-functions-core-tools@4/4.0.7030/workers/python/3.11/OSX/Arm64/azure_functions_worker/dispatcher.py", line 296, in _dispatch_grpc_request
    resp = await request_handler(request)
  File "/opt/homebrew/Cellar/azure-functions-core-tools@4/4.0.7030/workers/python/3.11/OSX/Arm64/azure_functions_worker/main.py", line 61, in main
    return asyncio.run(start_async(
  File "/opt/homebrew/Cellar/azure-functions-core-tools@4/4.0.7030/workers/python/3.11/OSX/Arm64/worker.py", line 68, in <module>
    main.main()
ValueError: time data '2025-04-11T00:27:53.569' does not match format '%Y-%m-%dT%H:%M:%S+00:00'

`

Attempts to monkey patch these internal functions from user code fail because the patching occurs too late in the worker's startup sequence.

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

1 participant