Skip to content

Commit 3558e00

Browse files
committed
feat: add _with_init to all triggers
1 parent 777c5d3 commit 3558e00

11 files changed

+21
-18
lines changed

src/firebase_functions/alerts_fn.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
import firebase_functions.private.util as _util
2626

27-
from firebase_functions.core import T, CloudEvent as _CloudEvent
27+
from firebase_functions.core import T, CloudEvent as _CloudEvent, _with_init
2828
from firebase_functions.options import FirebaseAlertOptions
2929

3030
# Explicitly import AlertType to make it available in the public API.
@@ -95,7 +95,7 @@ def on_alert_published_inner_decorator(func: OnAlertPublishedCallable):
9595
@_functools.wraps(func)
9696
def on_alert_published_wrapped(raw: _ce.CloudEvent):
9797
from firebase_functions.private._alerts_fn import alerts_event_from_ce
98-
func(alerts_event_from_ce(raw))
98+
_with_init(func)(alerts_event_from_ce(raw))
9999

100100
_util.set_func_endpoint_attr(
101101
on_alert_published_wrapped,

src/firebase_functions/db_fn.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ def _db_endpoint_handler(
119119
subject=event_attributes["subject"],
120120
params=params,
121121
)
122-
func(database_event)
122+
_core._with_init(func)(database_event)
123123

124124

125125
@_util.copy_func_kwargs(DatabaseOptions)

src/firebase_functions/eventarc_fn.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
import firebase_functions.options as _options
2323
import firebase_functions.private.util as _util
24-
from firebase_functions.core import CloudEvent
24+
from firebase_functions.core import CloudEvent, _with_init
2525

2626

2727
@_util.copy_func_kwargs(_options.EventarcTriggerOptions)
@@ -73,7 +73,7 @@ def on_custom_event_published_wrapped(raw: _ce.CloudEvent):
7373
),
7474
type=event_dict["type"],
7575
)
76-
func(event)
76+
_with_init(func)(event)
7777

7878
_util.set_func_endpoint_attr(
7979
on_custom_event_published_wrapped,

src/firebase_functions/firestore_fn.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ def _firestore_endpoint_handler(
173173
subject=event_attributes["subject"],
174174
params=params,
175175
)
176-
func(database_event)
176+
_core._with_init(func)(database_event)
177177

178178

179179
@_util.copy_func_kwargs(FirestoreOptions)

src/firebase_functions/https_fn.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ def _on_call_handler(func: _C2,
403403
instance_id_token=request.headers.get(
404404
"Firebase-Instance-ID-Token"),
405405
)
406-
result = func(context)
406+
result = _core._with_init(func)(context)
407407
return _jsonify(result=result)
408408
# Disable broad exceptions lint since we want to handle all exceptions here
409409
# and wrap as an HttpsError.
@@ -447,7 +447,7 @@ def on_request_wrapped(request: Request) -> Response:
447447
methods=options.cors.cors_methods,
448448
origins=options.cors.cors_origins,
449449
)(func)(request)
450-
return func(request)
450+
return _core._with_init(func)(request)
451451

452452
_util.set_func_endpoint_attr(
453453
on_request_wrapped,

src/firebase_functions/private/_identity_fn.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
import datetime as _dt
1919
import time as _time
2020
import json as _json
21+
22+
from firebase_functions.core import _with_init
2123
from firebase_functions.https_fn import HttpsError, FunctionsErrorCode
2224

2325
import firebase_functions.private.util as _util
@@ -351,7 +353,7 @@ def before_operation_handler(
351353
jwt_token = request.json["data"]["jwt"]
352354
decoded_token = _token_verifier.verify_auth_blocking_token(jwt_token)
353355
event = _auth_blocking_event_from_token_data(decoded_token)
354-
auth_response: BeforeCreateResponse | BeforeSignInResponse | None = func(
356+
auth_response: BeforeCreateResponse | BeforeSignInResponse | None = _with_init(func)(
355357
event)
356358
if not auth_response:
357359
return _jsonify({})

src/firebase_functions/pubsub_fn.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
import firebase_functions.private.util as _util
2727

28-
from firebase_functions.core import CloudEvent, T
28+
from firebase_functions.core import CloudEvent, T, _with_init
2929
from firebase_functions.options import PubSubOptions
3030

3131

@@ -151,7 +151,7 @@ def _message_handler(
151151
type=event_dict["type"],
152152
)
153153

154-
func(event)
154+
_with_init(func)(event)
155155

156156

157157
@_util.copy_func_kwargs(PubSubOptions)

src/firebase_functions/remote_config_fn.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
import firebase_functions.private.util as _util
2626

27-
from firebase_functions.core import CloudEvent
27+
from firebase_functions.core import CloudEvent, _with_init
2828
from firebase_functions.options import EventHandlerOptions
2929

3030

@@ -189,7 +189,7 @@ def _config_handler(func: _C1, raw: _ce.CloudEvent) -> None:
189189
type=event_dict["type"],
190190
)
191191

192-
func(event)
192+
_with_init(func)(event)
193193

194194

195195
@_util.copy_func_kwargs(EventHandlerOptions)

src/firebase_functions/scheduler_fn.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
make_response as _make_response,
2828
)
2929

30+
from firebase_functions.core import _with_init
3031
# Export for user convenience.
3132
# pylint: disable=unused-import
3233
from firebase_functions.options import Timezone
@@ -108,7 +109,7 @@ def on_schedule_wrapped(request: _Request) -> _Response:
108109
schedule_time=schedule_time,
109110
)
110111
try:
111-
func(event)
112+
_with_init(func)(event)
112113
return _make_response()
113114
# Disable broad exceptions lint since we want to handle all exceptions.
114115
# pylint: disable=broad-except

src/firebase_functions/storage_fn.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
import cloudevents.http as _ce
2323

2424
import firebase_functions.private.util as _util
25-
from firebase_functions.core import CloudEvent
25+
from firebase_functions.core import CloudEvent, _with_init
2626
from firebase_functions.options import StorageOptions
2727

2828
_event_type_archived = "google.cloud.storage.object.v1.archived"
@@ -255,7 +255,7 @@ def _message_handler(
255255
type=event_attributes["type"],
256256
)
257257

258-
func(event)
258+
_with_init(func)(event)
259259

260260

261261
@_util.copy_func_kwargs(StorageOptions)

src/firebase_functions/test_lab_fn.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
import firebase_functions.private.util as _util
2626

27-
from firebase_functions.core import CloudEvent
27+
from firebase_functions.core import CloudEvent, _with_init
2828
from firebase_functions.options import EventHandlerOptions
2929

3030

@@ -246,7 +246,7 @@ def _event_handler(func: _C1, raw: _ce.CloudEvent) -> None:
246246
type=event_dict["type"],
247247
)
248248

249-
func(event)
249+
_with_init(func)(event)
250250

251251

252252
@_util.copy_func_kwargs(EventHandlerOptions)

0 commit comments

Comments
 (0)