I’m trying to run a google cloud function every day. Currently I am using the following code to have a scheduler that regularly invokes a private function.
@scheduler_fn.on_schedule(memory=options.MemoryOption.MB_512,
timeout_sec=60, schedule='0 19 * * 0,1,2,3,4',
timezone=Timezone('America/New_York'))
def enqueue_update_all_data(event: scheduler_fn.ScheduledEvent) -> None:
target_url = __get_function_url('update_all_data', options.SupportedRegion.US_CENTRAL1.value)
auth_req = google_requests.Request()
audience = target_url
id_token = google_id_token.fetch_id_token(auth_req, audience)
headers = {'Authorization': f'Bearer {id_token}'}
# Trigger Cloud Function but don't wait for response.
try:
requests.get(target_url, headers=headers, timeout=10)
except requests.exceptions.Timeout:
pass
def __get_function_url(name: str, location: str) -> str:
credentials, project_id = google.auth.default(scopes=["https://www.googleapis.com/auth/cloud-platform"])
authed_session = google_requests.AuthorizedSession(credentials)
url = (f"https://cloudfunctions.googleapis.com/v2/projects/{project_id}/locations/{location}/functions/{name}")
response = authed_session.get(url)
data = response.json()
function_url = data["serviceConfig"]["uri"]
return function_url
@https_fn.on_request(
memory=options.MemoryOption.GB_16,
timeout_sec=3600,
max_instances=1,
invoker="private",
)
def update_all_data(req: Request) -> Response:
...
Whenever this runs using the cron job, it gives an error as follows. This is from thursday, but it does this every night.
Traceback (most recent call last):
File "/layers/google.python.pip/pip/lib/python3.11/site-packages/flask/app.py", line 1511, in wsgi_app
response = self.full_dispatch_request()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/layers/google.python.pip/pip/lib/python3.11/site-packages/flask/app.py", line 919, in full_dispatch_request
rv = self.handle_user_exception(e)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/layers/google.python.pip/pip/lib/python3.11/site-packages/flask/app.py", line 917, in full_dispatch_request
rv = self.dispatch_request()
^^^^^^^^^^^^^^^^^^^^^^^
File "/layers/google.python.pip/pip/lib/python3.11/site-packages/flask/app.py", line 902, in dispatch_request
return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args) # type: ignore[no-any-return]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/layers/google.python.pip/pip/lib/python3.11/site-packages/functions_framework/execution_id.py", line 157, in wrapper
result = view_function(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/layers/google.python.pip/pip/lib/python3.11/site-packages/functions_framework/__init__.py", line 142, in view_func
return function(request._get_current_object())
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/layers/google.python.pip/pip/lib/python3.11/site-packages/firebase_functions/scheduler_fn.py", line 103, in on_schedule_wrapped
schedule_time = _dt.datetime.strptime(
^^^^^^^^^^^^^^^^^^^^^^
File "/layers/google.python.runtime/python/lib/python3.11/_strptime.py", line 567, in _strptime_datetime
tt, fraction, gmtoff_fraction = _strptime(data_string, format)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/layers/google.python.runtime/python/lib/python3.11/_strptime.py", line 349, in _strptime
raise ValueError("time data %r does not match format %r" %
ValueError: time data '2026-05-21T16:00:03.774441-07:00' does not match format '%Y-%m-%dT%H:%M:%S%z'
I am not sure how to fix this, since none of the files in the stack trace are under my control. They are all installed by pip.
I have tried redeploying (many many times), upgrading flask, upgrading firebase_functions, and upgrading python. The error has remained unchanged.
I know that the problem is not the update_all_data function. It runs fine in local emulators and when triggered manually by curl.
I haven’t tried unifying the functions to have the business logic inside the scheduled function because it seems like the .on_schedule does not work regardless of what I put in there.
I cannot explain this error and have been completely unable to find other information online. Any help is appreciated.