From a274f474af99c4310fb9b961ab2ef6b014d687f0 Mon Sep 17 00:00:00 2001 From: exaby73 Date: Wed, 3 Jul 2024 07:58:19 +0530 Subject: [PATCH 1/3] fix: incorrect type for document snapshop in Firestore auth triggers --- src/firebase_functions/firestore_fn.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/firebase_functions/firestore_fn.py b/src/firebase_functions/firestore_fn.py index 8e5632d..e4a0e98 100644 --- a/src/firebase_functions/firestore_fn.py +++ b/src/firebase_functions/firestore_fn.py @@ -169,13 +169,18 @@ def _firestore_endpoint_handler( firestore_event_data.old_value.create_time, firestore_event_data.old_value.update_time, ) - if event_type == _event_type_deleted: + print(f"Event type: {event_type}") + if event_type in (_event_type_deleted, + _event_type_deleted_with_auth_context): firestore_event_data = _typing.cast(_firestore.DocumentEventData, old_value_snapshot) - if event_type == _event_type_created: + if event_type in (_event_type_created, + _event_type_created_with_auth_context): firestore_event_data = _typing.cast(_firestore.DocumentEventData, value_snapshot) - if event_type in (_event_type_written, _event_type_updated): + if event_type in (_event_type_written, _event_type_updated, + _event_type_written_with_auth_context, + _event_type_updated_with_auth_context): firestore_event_data = _typing.cast( _firestore.DocumentEventData, Change( From 3fe71df191c980cbcf5c4f04fe03dec1b1002fbb Mon Sep 17 00:00:00 2001 From: exaby73 Date: Tue, 9 Jul 2024 11:00:34 +0530 Subject: [PATCH 2/3] fix: remove print statement --- src/firebase_functions/firestore_fn.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/firebase_functions/firestore_fn.py b/src/firebase_functions/firestore_fn.py index e4a0e98..6fa417f 100644 --- a/src/firebase_functions/firestore_fn.py +++ b/src/firebase_functions/firestore_fn.py @@ -143,7 +143,8 @@ def _firestore_endpoint_handler( app = get_app() firestore_client = _firestore_v1.Client(project=app.project_id, database=event_database) - firestore_ref: DocumentReference = firestore_client.document(event_document) + firestore_ref: DocumentReference = firestore_client.document( + event_document) value_snapshot: DocumentSnapshot | None = None old_value_snapshot: DocumentSnapshot | None = None @@ -169,7 +170,7 @@ def _firestore_endpoint_handler( firestore_event_data.old_value.create_time, firestore_event_data.old_value.update_time, ) - print(f"Event type: {event_type}") + if event_type in (_event_type_deleted, _event_type_deleted_with_auth_context): firestore_event_data = _typing.cast(_firestore.DocumentEventData, @@ -272,7 +273,7 @@ def on_document_written_wrapped(raw: _ce.CloudEvent): @_util.copy_func_kwargs(FirestoreOptions) def on_document_written_with_auth_context(**kwargs - ) -> _typing.Callable[[_C1], _C1]: + ) -> _typing.Callable[[_C1], _C1]: """ Event handler that triggers when a document is created, updated, or deleted in Firestore. This trigger will also provide the authentication context of the principal who triggered @@ -371,7 +372,7 @@ def on_document_updated_wrapped(raw: _ce.CloudEvent): @_util.copy_func_kwargs(FirestoreOptions) def on_document_updated_with_auth_context(**kwargs - ) -> _typing.Callable[[_C1], _C1]: + ) -> _typing.Callable[[_C1], _C1]: """ Event handler that triggers when a document is updated in Firestore. This trigger will also provide the authentication context of the principal who triggered @@ -470,7 +471,7 @@ def on_document_created_wrapped(raw: _ce.CloudEvent): @_util.copy_func_kwargs(FirestoreOptions) def on_document_created_with_auth_context(**kwargs - ) -> _typing.Callable[[_C2], _C2]: + ) -> _typing.Callable[[_C2], _C2]: """ Event handler that triggers when a document is created in Firestore. This trigger will also provide the authentication context of the principal who triggered @@ -569,7 +570,7 @@ def on_document_deleted_wrapped(raw: _ce.CloudEvent): @_util.copy_func_kwargs(FirestoreOptions) def on_document_deleted_with_auth_context(**kwargs - ) -> _typing.Callable[[_C2], _C2]: + ) -> _typing.Callable[[_C2], _C2]: """ Event handler that triggers when a document is deleted in Firestore. This trigger will also provide the authentication context of the principal who triggered From e5a23234b44f762cc9c5945b0f33f78af79ee887 Mon Sep 17 00:00:00 2001 From: exaby73 Date: Tue, 9 Jul 2024 11:03:03 +0530 Subject: [PATCH 3/3] fix: formatting --- src/firebase_functions/firestore_fn.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/firebase_functions/firestore_fn.py b/src/firebase_functions/firestore_fn.py index 6fa417f..3e6faa4 100644 --- a/src/firebase_functions/firestore_fn.py +++ b/src/firebase_functions/firestore_fn.py @@ -143,8 +143,7 @@ def _firestore_endpoint_handler( app = get_app() firestore_client = _firestore_v1.Client(project=app.project_id, database=event_database) - firestore_ref: DocumentReference = firestore_client.document( - event_document) + firestore_ref: DocumentReference = firestore_client.document(event_document) value_snapshot: DocumentSnapshot | None = None old_value_snapshot: DocumentSnapshot | None = None @@ -273,7 +272,7 @@ def on_document_written_wrapped(raw: _ce.CloudEvent): @_util.copy_func_kwargs(FirestoreOptions) def on_document_written_with_auth_context(**kwargs - ) -> _typing.Callable[[_C1], _C1]: + ) -> _typing.Callable[[_C1], _C1]: """ Event handler that triggers when a document is created, updated, or deleted in Firestore. This trigger will also provide the authentication context of the principal who triggered @@ -372,7 +371,7 @@ def on_document_updated_wrapped(raw: _ce.CloudEvent): @_util.copy_func_kwargs(FirestoreOptions) def on_document_updated_with_auth_context(**kwargs - ) -> _typing.Callable[[_C1], _C1]: + ) -> _typing.Callable[[_C1], _C1]: """ Event handler that triggers when a document is updated in Firestore. This trigger will also provide the authentication context of the principal who triggered @@ -471,7 +470,7 @@ def on_document_created_wrapped(raw: _ce.CloudEvent): @_util.copy_func_kwargs(FirestoreOptions) def on_document_created_with_auth_context(**kwargs - ) -> _typing.Callable[[_C2], _C2]: + ) -> _typing.Callable[[_C2], _C2]: """ Event handler that triggers when a document is created in Firestore. This trigger will also provide the authentication context of the principal who triggered @@ -570,7 +569,7 @@ def on_document_deleted_wrapped(raw: _ce.CloudEvent): @_util.copy_func_kwargs(FirestoreOptions) def on_document_deleted_with_auth_context(**kwargs - ) -> _typing.Callable[[_C2], _C2]: + ) -> _typing.Callable[[_C2], _C2]: """ Event handler that triggers when a document is deleted in Firestore. This trigger will also provide the authentication context of the principal who triggered