Azure / azure-functions-python-worker

Python worker for Azure Functions.
http://aka.ms/azurefunctions
MIT License
335 stars 103 forks source link

Eventgrid binding will fail due to timestamp format ('2024-07-26T06:53:34.161' does not match format '%Y-%m-%dT%H:%M:%S+00:00') #1549

Closed MiguelElGallo closed 3 months ago

MiguelElGallo commented 3 months ago

Expected Behavior

There is no customer code, is just a decorator:

@bp.event_hub_message_trigger(
    arg_name="event",
    event_hub_name="dummy",   
    connection="EVENTHUBCONNECTIONSTRING1",  
    consumer_group=consumergroup,
)
def First_trigger(event: func.EventHubEvent, context: func.Context) -> None:

Expected behaviour is that instead of an error it would execute the First_trigger.

Actual Behavior

When an event is received from the event hub it fails with the error:

Azure/azure-functions-python-workertime data '2024-07-26T06:53:34.161' does not match format '%Y-%m-%dT%H:%M:%S+00:00'
  File "/opt/homebrew/Cellar/azure-functions-core-tools@4/4.0.5907/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.5907/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.5907/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.5907/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.5907/workers/python/3.11/OSX/Arm64/azure/functions/eventhub.py", line 127, in decode_single_event
    enqueued_time=cls._parse_datetime_metadata(
  File "/opt/homebrew/Cellar/azure-functions-core-tools@4/4.0.5907/workers/python/3.11/OSX/Arm64/azure/functions/eventhub.py", line 105, in decode
    return cls.decode_single_event(data, trigger_metadata)
  File "/opt/homebrew/Cellar/azure-functions-core-tools@4/4.0.5907/workers/python/3.11/OSX/Arm64/azure_functions_worker/bindings/meta.py", line 188, in from_incoming_proto
    return binding.decode(datum, trigger_metadata=metadata)
  File "/opt/homebrew/Cellar/azure-functions-core-tools@4/4.0.5907/workers/python/3.11/OSX/Arm64/azure_functions_worker/dispatcher.py", line 565, in _handle__invocation_request
    args[pb.name] = bindings.from_incoming_proto(
  File "/opt/homebrew/Cellar/azure-functions-core-tools@4/4.0.5907/workers/python/3.11/OSX/Arm64/azure_functions_worker/dispatcher.py", line 274, in _dispatch_grpc_request
    resp = await request_handler(request)
  File "/opt/homebrew/Cellar/azure-functions-core-tools@4/4.0.5907/workers/python/3.11/OSX/Arm64/azure_functions_worker/main.py", line 60, in main
    return asyncio.run(start_async(
  File "/opt/homebrew/Cellar/azure-functions-core-tools@4/4.0.5907/workers/python/3.11/OSX/Arm64/worker.py", line 71, in <module>
    main.main()
ValueError: time data '2024-07-26T06:53:34.161' does not match format '%Y-%m-%dT%H:%M:%S+00:00'

Steps to Reproduce

1 Create a function like:

@bp.event_hub_message_trigger(
    arg_name="event",
    event_hub_name="dummy",   
    connection="EVENTHUBCONNECTIONSTRING1",  
    consumer_group=consumergroup,
)
def First_trigger(event: func.EventHubEvent, context: func.Context) -> None:
  1. Connect a Blob a storage event grid to and eventhub.

  2. Drop a file in the Blob storage.

Relevant code being tried

@bp.event_hub_message_trigger(
    arg_name="event",
    event_hub_name="dummy",   
    connection="EVENTHUBCONNECTIONSTRING1",  
    consumer_group=consumergroup,
)
def First_trigger(event: func.EventHubEvent, context: func.Context) -> None:

Relevant log output

Azure/azure-functions-python-workertime data '2024-07-26T06:53:34.161' does not match format '%Y-%m-%dT%H:%M:%S+00:00'
  File "/opt/homebrew/Cellar/azure-functions-core-tools@4/4.0.5907/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.5907/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.5907/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.5907/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.5907/workers/python/3.11/OSX/Arm64/azure/functions/eventhub.py", line 127, in decode_single_event
    enqueued_time=cls._parse_datetime_metadata(
  File "/opt/homebrew/Cellar/azure-functions-core-tools@4/4.0.5907/workers/python/3.11/OSX/Arm64/azure/functions/eventhub.py", line 105, in decode
    return cls.decode_single_event(data, trigger_metadata)
  File "/opt/homebrew/Cellar/azure-functions-core-tools@4/4.0.5907/workers/python/3.11/OSX/Arm64/azure_functions_worker/bindings/meta.py", line 188, in from_incoming_proto
    return binding.decode(datum, trigger_metadata=metadata)
  File "/opt/homebrew/Cellar/azure-functions-core-tools@4/4.0.5907/workers/python/3.11/OSX/Arm64/azure_functions_worker/dispatcher.py", line 565, in _handle__invocation_request
    args[pb.name] = bindings.from_incoming_proto(
  File "/opt/homebrew/Cellar/azure-functions-core-tools@4/4.0.5907/workers/python/3.11/OSX/Arm64/azure_functions_worker/dispatcher.py", line 274, in _dispatch_grpc_request
    resp = await request_handler(request)
  File "/opt/homebrew/Cellar/azure-functions-core-tools@4/4.0.5907/workers/python/3.11/OSX/Arm64/azure_functions_worker/main.py", line 60, in main
    return asyncio.run(start_async(
  File "/opt/homebrew/Cellar/azure-functions-core-tools@4/4.0.5907/workers/python/3.11/OSX/Arm64/worker.py", line 71, in <module>
    main.main()
ValueError: time data '2024-07-26T06:53:34.161' does not match format '%Y-%m-%dT%H:%M:%S+00:00'

requirements.txt file

# This file was autogenerated by uv via the following command:
#    uv pip compile requirements.in --output-file=requirements.txt
adenotifier @ git+https://github.com/solita/adenotifier.git@b54ee1a28cac2e2bd74a90f55355d23b2ed485b2
    # via -r requirements.in
annotated-types==0.7.0
    # via pydantic
asgiref==3.8.1
    # via opentelemetry-instrumentation-asgi
asn1crypto==1.5.1
    # via snowflake-connector-python
azure-core==1.30.2
    # via
    #   azure-core-tracing-opentelemetry
    #   azure-eventhub
    #   azure-identity
    #   azure-keyvault-secrets
    #   azure-monitor-opentelemetry
    #   azure-monitor-opentelemetry-exporter
    #   msrest
azure-core-tracing-opentelemetry==1.0.0b11
    # via azure-monitor-opentelemetry
azure-eventhub==5.12.1
    # via -r requirements.in
azure-functions==1.20.0
    # via -r requirements.in
azure-identity==1.17.1
    # via -r requirements.in
azure-keyvault-secrets==4.8.0
    # via -r requirements.in
azure-monitor-opentelemetry==1.6.0
    # via -r requirements.in
azure-monitor-opentelemetry-exporter==1.0.0b27
    # via azure-monitor-opentelemetry
certifi==2024.7.4
    # via
    #   msrest
    #   requests
    #   snowflake-connector-python
cffi==1.16.0
    # via
    #   cryptography
    #   snowflake-connector-python
charset-normalizer==3.3.2
    # via
    #   requests
    #   snowflake-connector-python
cryptography==42.0.8
    # via
    #   azure-identity
    #   msal
    #   pyjwt
    #   pyopenssl
    #   snowflake-connector-python
deprecated==1.2.14
    # via
    #   opentelemetry-api
    #   opentelemetry-semantic-conventions
filelock==3.15.4
    # via snowflake-connector-python
fixedint==0.1.6
    # via azure-monitor-opentelemetry-exporter
idna==3.7
    # via
    #   requests
    #   snowflake-connector-python
importlib-metadata==8.0.0
    # via
    #   opentelemetry-api
    #   opentelemetry-instrumentation-flask
isodate==0.6.1
    # via
    #   azure-keyvault-secrets
    #   msrest
msal==1.30.0
    # via
    #   azure-identity
    #   msal-extensions
msal-extensions==1.2.0
    # via azure-identity
msrest==0.7.1
    # via azure-monitor-opentelemetry-exporter
oauthlib==3.2.2
    # via requests-oauthlib
opentelemetry-api==1.26.0
    # via
    #   azure-core-tracing-opentelemetry
    #   azure-monitor-opentelemetry-exporter
    #   opentelemetry-instrumentation
    #   opentelemetry-instrumentation-asgi
    #   opentelemetry-instrumentation-dbapi
    #   opentelemetry-instrumentation-django
    #   opentelemetry-instrumentation-fastapi
    #   opentelemetry-instrumentation-flask
    #   opentelemetry-instrumentation-psycopg2
    #   opentelemetry-instrumentation-requests
    #   opentelemetry-instrumentation-urllib
    #   opentelemetry-instrumentation-urllib3
    #   opentelemetry-instrumentation-wsgi
    #   opentelemetry-sdk
    #   opentelemetry-semantic-conventions
opentelemetry-instrumentation==0.47b0
    # via
    #   opentelemetry-instrumentation-asgi
    #   opentelemetry-instrumentation-dbapi
    #   opentelemetry-instrumentation-django
    #   opentelemetry-instrumentation-fastapi
    #   opentelemetry-instrumentation-flask
    #   opentelemetry-instrumentation-psycopg2
    #   opentelemetry-instrumentation-requests
    #   opentelemetry-instrumentation-urllib
    #   opentelemetry-instrumentation-urllib3
    #   opentelemetry-instrumentation-wsgi
opentelemetry-instrumentation-asgi==0.47b0
    # via opentelemetry-instrumentation-fastapi
opentelemetry-instrumentation-dbapi==0.47b0
    # via opentelemetry-instrumentation-psycopg2
opentelemetry-instrumentation-django==0.47b0
    # via azure-monitor-opentelemetry
opentelemetry-instrumentation-fastapi==0.47b0
    # via azure-monitor-opentelemetry
opentelemetry-instrumentation-flask==0.47b0
    # via azure-monitor-opentelemetry
opentelemetry-instrumentation-psycopg2==0.47b0
    # via azure-monitor-opentelemetry
opentelemetry-instrumentation-requests==0.47b0
    # via azure-monitor-opentelemetry
opentelemetry-instrumentation-urllib==0.47b0
    # via azure-monitor-opentelemetry
opentelemetry-instrumentation-urllib3==0.47b0
    # via azure-monitor-opentelemetry
opentelemetry-instrumentation-wsgi==0.47b0
    # via
    #   opentelemetry-instrumentation-django
    #   opentelemetry-instrumentation-flask
opentelemetry-resource-detector-azure==0.1.5
    # via azure-monitor-opentelemetry
opentelemetry-sdk==1.26.0
    # via
    #   azure-monitor-opentelemetry
    #   azure-monitor-opentelemetry-exporter
    #   opentelemetry-resource-detector-azure
opentelemetry-semantic-conventions==0.47b0
    # via
    #   opentelemetry-instrumentation-asgi
    #   opentelemetry-instrumentation-dbapi
    #   opentelemetry-instrumentation-django
    #   opentelemetry-instrumentation-fastapi
    #   opentelemetry-instrumentation-flask
    #   opentelemetry-instrumentation-requests
    #   opentelemetry-instrumentation-urllib
    #   opentelemetry-instrumentation-urllib3
    #   opentelemetry-instrumentation-wsgi
    #   opentelemetry-sdk
opentelemetry-util-http==0.47b0
    # via
    #   opentelemetry-instrumentation-asgi
    #   opentelemetry-instrumentation-django
    #   opentelemetry-instrumentation-fastapi
    #   opentelemetry-instrumentation-flask
    #   opentelemetry-instrumentation-requests
    #   opentelemetry-instrumentation-urllib
    #   opentelemetry-instrumentation-urllib3
    #   opentelemetry-instrumentation-wsgi
packaging==24.1
    # via
    #   opentelemetry-instrumentation-flask
    #   snowflake-connector-python
platformdirs==4.2.2
    # via snowflake-connector-python
polars==1.2.1
    # via -r requirements.in
portalocker==2.10.1
    # via msal-extensions
psutil==5.9.8
    # via azure-monitor-opentelemetry-exporter
pycparser==2.22
    # via cffi
pydantic==2.8.2
    # via
    #   -r requirements.in
    #   pydantic-settings
pydantic-core==2.20.1
    # via pydantic
pydantic-settings==2.3.4
    # via -r requirements.in
pyjwt==2.8.0
    # via
    #   msal
    #   snowflake-connector-python
pyopenssl==24.2.1
    # via snowflake-connector-python
python-dotenv==1.0.1
    # via
    #   -r requirements.in
    #   pydantic-settings
pytz==2024.1
    # via snowflake-connector-python
requests==2.32.3
    # via
    #   adenotifier
    #   azure-core
    #   msal
    #   msrest
    #   requests-oauthlib
    #   snowflake-connector-python
requests-oauthlib==2.0.0
    # via msrest
setuptools==71.1.0
    # via opentelemetry-instrumentation
six==1.16.0
    # via
    #   azure-core
    #   isodate
snowflake-connector-python==3.12.0
    # via snowflake-sqlalchemy
snowflake-sqlalchemy==1.6.1
    # via -r requirements.in
sortedcontainers==2.4.0
    # via snowflake-connector-python
sqlalchemy==2.0.31
    # via snowflake-sqlalchemy
tenacity==8.5.0
    # via -r requirements.in
tomlkit==0.13.0
    # via snowflake-connector-python
typing-extensions==4.12.2
    # via
    #   azure-core
    #   azure-eventhub
    #   azure-identity
    #   azure-keyvault-secrets
    #   opentelemetry-sdk
    #   pydantic
    #   pydantic-core
    #   snowflake-connector-python
    #   sqlalchemy
urllib3==2.2.2
    # via requests
wrapt==1.16.0
    # via
    #   deprecated
    #   opentelemetry-instrumentation
    #   opentelemetry-instrumentation-dbapi
    #   opentelemetry-instrumentation-urllib3
zipp==3.19.2
    # via importlib-metadata

Where are you facing this problem?

Local - Core Tools

Function app name

No response

Additional Information

This was working 2 months, ago , I have only updated the core-tools, and libraries, and now it does not work

MiguelElGallo commented 3 months ago

I will be closing this, this happened because I had in VSCode enabled breakpoints: "Raised Exceptions".