Azure / Azure/azure-functions-python-worker

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

Offen
#1,731 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
area:python-functions Needs: Triage (Functions) python-sdk
Vorherrschende Sprache
Python
Sterne
357
Forks
116
Ø Merge
32 Min.
Gemergte PRs (30 T.)
1

Beschreibung

### 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
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.

Beitragsleitfaden

Beitragsleitfaden öffnen

Rechercherichtung

Beginne mit azure/functions/_utils.py und verfolge den datetime-Parsing-Pfad über meta.py bis zu decode_single_message in servicebus.py. Reproduziere das gezeigte Zeitstempelformat und überprüfe, dass die Dekodierung von Service Bus-Nachrichten es akzeptiert und die Funktion des Benutzers ohne einen ValueError erreicht.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
python
Bereich
backend, cloud
Issue-Typ
Bug
Schwierigkeit
3/5
Geschätzter Aufwand
1-2 Tage
Aktivitätsstatus
Veraltet
Klarheit
Klar beschrieben
Anfängerfreundlichkeit
55/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.