Azure / Azure/azure-functions-python-worker

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

オープン
#1,731 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る
area:python-functions Needs: Triage (Functions) python-sdk
主要言語
Python
スター
357
フォーク
116
平均マージ
32分
マージ済み PR(30日)
1

説明

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

コントリビューションガイド

コントリビューションガイドを開く

調査の方向性

azure/functions/_utils.py から始め、meta.py を経由して servicebus.py の decode_single_message まで datetime の解析経路を追跡します。示されているタイムスタンプ形式を再現し、Service Bus メッセージのデコードがそれを受け入れ、ValueError なしでユーザーの関数に到達することを確認します。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
python
領域
backend, cloud
issue の種類
バグ
難易度
3/5
見積もり時間
1〜2日
活発さ
停滞
明瞭さ
明確に書かれている
初心者へのやさしさ
55/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。