10000 Event Time parse issue in firestore_fn.py · Issue #95 · firebase/firebase-functions-python · GitHub
[go: up one dir, main page]

Skip to content
Event Time parse issue in firestore_fn.py #95
Closed
@noonzyism

Description

@noonzyism

I'm following the start guide at: https://firebase.google.com/docs/functions/get-started?gen=2nd

At step 7, when testing the functions using the emulator, the addmessage function works fine, and triggers the makeuppercase function appropriately, but the makeuppercase call fails with an error related to event datetime:

i  functions: Beginning execution of "us-central1-addmessage"
>  127.0.0.1 - - [21/May/2023 01:57:15] "GET /?text=newmessage HTTP/1.1" 200 -
i  functions: Finished "us-central1-addmessage" in 105.1165ms
>   * Serving Flask app 'makeuppercase'
>   * Debug mode: off
>  WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead.
>   * Running on http://127.0.0.1:8933
>  Press CTRL+C to quit
>  127.0.0.1 - - [21/May/2023 01:57:16] "GET /__/health HTTP/1.1" 405 -
i  functions: Beginning execution of "us-central1-makeuppercase"
>  [2023-05-21 01:57:16,487] ERROR in app: Exception on /functions/projects/ [POST]
>  Traceback (most recent call last):
>    File "C:\Users\user\proj\functions\venv\Lib\site-packages\flask\app.py", line 2190, in wsgi_app
>      response = self.full_dispatch_request()
>                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>    File "C:\Users\user\proj\functions\venv\Lib\site-packages\flask\app.py", line 1486, in full_dispatch_request
>      rv = self.handle_user_exception(e)
>           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>    File "C:\Users\user\proj\functions\venv\Lib\site-packages\flask\app.py", line 1484, in full_dispatch_request
>      rv = self.dispatch_request()
>           ^^^^^^^^^^^^^^^^^^^^^^^
>    File "C:\Users\user\proj\functions\venv\Lib\site-packages\flask\app.py", line 1469, in dispatch_request
>      return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)
>             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>    File "C:\Users\user\proj\functions\venv\Lib\site-packages\functions_framework\__init__.py", line 174, in view_func
>      function(event)
>    File "C:\Users\user\proj\functions\venv\Lib\site-packages\firebase_functions\firestore_fn.py", line 302, in on_document_created_wrapped
>      return _firestore_endpoint_handler(
>             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>    File "C:\Users\user\proj\functions\venv\Lib\site-packages\firebase_functions\firestore_fn.py", line 114, in _firestore_endpoint_handler
>      event_time = _dt.datetime.strptime(
>                   ^^^^^^^^^^^^^^^^^^^^^^
>    File "C:\Python311\Lib\_strptime.py", line 568, in _strptime_datetime
>      tt, fraction, gmtoff_fraction = _strptime(data_string, format)
>                                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>    File "C:\Python311\Lib\_strptime.py", line 349, in _strptime
>      raise ValueError("time data %r does not match format %r" %
>  ValueError: time data '2023-05-21T01:57:15.643674100Z' does not match format '%Y-%m-%dT%H:%M:%S.%f%z'
i  functions: Finished "us-central1-makeuppercase" in 22.0598ms
>  127.0.0.1 - - [21/May/2023 01:57:16] "POST /functions/projects/ HTTP/1.1" 500 -

FWIW, I was able to hack around it locally by modifying firestore_fn.py to use dateutil.parser instead and changing line 114:

import dateutil.parser as dateutil

Line 114:

event_time = dateutil.parse(event_attributes["time"])

Not sure if this would be the most appropriate fix for the repo, or if there's some other underlying root cause that should be addressed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0