-
Notifications
You must be signed in to change notification settings - Fork 30
Description
Hello, I ‘ve been trying to test a locally deployed google cloud function that looks like this:
@storage_fn.on_object_finalized(bucket=MY_BUCKET)
def finalized_bucket(
cloud_event: storage_fn.CloudEvent[storage_fn.StorageObjectData]
) -> None:
print("triggered!")
return "ok"
My gcloud command to deploy the function is this one:
gcloud alpha functions local deploy example \
--gen2 \
--entry-point=finalized_bucket \
--runtime=python312 \
--port 8083 \
--env-vars-file="../../.env.local.yml"
The function is deployed successfully and then I am testing it with:
curl localhost:8083 \
-X POST \
-H "Content-Type: application/json" \
-d '{
"context": {
"eventId": "1147091835525187",
"timestamp": "2020-04-23T07:38:57.772Z",
"eventType": "google.storage.object.finalize",
"resource": {
"service": "storage.googleapis.com",
"name": "projects/_/buckets/MY_BUCKET/MY_FILE.txt",
"type": "storage#object"
}
},
"data": {
"bucket": "MY_BUCKET",
"contentType": "text/plain",
"kind": "storage#object",
"md5Hash": "...",
"metageneration": "1",
"name": "MY_FILE.txt",
"size": "352",
"storageClass": "MULTI_REGIONAL",
"timeCreated": "2020-04-23T07:38:57.230Z",
"timeStorageClassUpdated": "2020-04-23T07:38:57.230Z",
"updated": "2020-04-23T07:38:57.230Z"
}
}'
Then, I get the following error (from the logs):
2024-04-17 00:12:40 [2024-04-16 22:12:40,786] ERROR in app: Exception on / [POST]
2024-04-17 00:12:40 Traceback (most recent call last):
2024-04-17 00:12:40 File "/layers/google.python.pip/pip/lib/python3.12/site-packages/flask/app.py", line 1473, in wsgi_app
2024-04-17 00:12:40 response = self.full_dispatch_request()
2024-04-17 00:12:40 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2024-04-17 00:12:40 File "/layers/google.python.pip/pip/lib/python3.12/site-packages/flask/app.py", line 882, in full_dispatch_request
2024-04-17 00:12:40 rv = self.handle_user_exception(e)
2024-04-17 00:12:40 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2024-04-17 00:12:40 File "/layers/google.python.pip/pip/lib/python3.12/site-packages/flask/app.py", line 880, in full_dispatch_request
2024-04-17 00:12:40 rv = self.dispatch_request()
2024-04-17 00:12:40 ^^^^^^^^^^^^^^^^^^^^^^^
2024-04-17 00:12:40 File "/layers/google.python.pip/pip/lib/python3.12/site-packages/flask/app.py", line 865, in dispatch_request
2024-04-17 00:12:40 return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args) # type: ignore[no-any-return]
2024-04-17 00:12:40 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2024-04-17 00:12:40 File "/layers/google.python.pip/pip/lib/python3.12/site-packages/functions_framework/__init__.py", line 134, in view_func
2024-04-17 00:12:40 return function(request._get_current_object())
2024-04-17 00:12:40 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2024-04-17 00:12:40 File "/layers/google.python.pip/pip/lib/python3.12/site-packages/firebase_functions/storage_fn.py", line 332, in on_object_finalized_wrapped
2024-04-17 00:12:40 return _message_handler(func, raw)
2024-04-17 00:12:40 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
2024-04-17 00:12:40 File "/layers/google.python.pip/pip/lib/python3.12/site-packages/firebase_functions/storage_fn.py", line 206, in _message_handler
2024-04-17 00:12:40 event_attributes = raw._get_attributes()
2024-04-17 00:12:40 ^^^^^^^^^^^^^^^^^^^
2024-04-17 00:12:40 AttributeError: 'Request' object has no attribute '_get_attributes'. Did you mean: '__getattribute__'?
Additionally, when I test its actual functionality (do something when an object is added to the bucket) there is nothing happening (no event triggered). The storage bucket I am using is running on firebase emulator. I am using the ‘STORAGE_EMULATOR_HOST’ environment variable and I initialise the app with the emulator-adapted project id. The deployed function can read the bucket’s contents (I can print a list of the blobs when I spin it up), but the function is not triggered when I am adding a new file, meaning that I am not receiving the above error either.
I tried with different versions of firebase-functions: 0.4.0, 0.3.0, 0.2.0 and I still get the same behaviour.
Any help would be appreciated.
Thanks