firebase-functions-python
firebase-functions-python copied to clipboard
Cannot set invoker to public for HTTP request function
According to the typing of HttpsOptions
class, I should be able to set invoker
to public
or private
. But when I tried to deploy a https_fn.on_request
function with invoker=True
, an error is raised:
[2024-03-06 02:26:16,162] ERROR in app: Exception on /__/functions.yaml [GET]
Traceback (most recent call last):
File "/Volumes/Cased/Projects/cloud-functions/functions/.venv/lib/python3.11/site-packages/flask/app.py", line 1463, in wsgi_app
response = self.full_dispatch_request()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Volumes/Cased/Projects/cloud-functions/functions/.venv/lib/python3.11/site-packages/flask/app.py", line 872, in full_dispatch_request
rv = self.handle_user_exception(e)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Volumes/Cased/Projects/cloud-functions/functions/.venv/lib/python3.11/site-packages/flask/app.py", line 870, in full_dispatch_request
rv = self.dispatch_request()
^^^^^^^^^^^^^^^^^^^^^^^
File "/Volumes/Cased/Projects/cloud-functions/functions/.venv/lib/python3.11/site-packages/flask/app.py", line 855, in dispatch_request
return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args) # type: ignore[no-any-return]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Volumes/Cased/Projects/cloud-functions/functions/.venv/lib/python3.11/site-packages/firebase_functions/private/serving.py", line 122, in get_functions_yaml
functions = get_functions()
^^^^^^^^^^^^^^^
File "/Volumes/Cased/Projects/cloud-functions/functions/.venv/lib/python3.11/site-packages/firebase_functions/private/serving.py", line 40, in get_functions
spec.loader.exec_module(module)
File "<frozen importlib._bootstrap_external>", line 940, in exec_module
File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
File "/Volumes/Cased/Projects/cloud-functions/functions/main.py", line 29, in <module>
@https_fn.on_request(invoker="public", memory=options.MemoryOption.MB_512)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Volumes/Cased/Projects/cloud-functions/functions/.venv/lib/python3.11/site-packages/firebase_functions/https_fn.py", line 443, in on_request_inner_decorator
options._endpoint(func_name=func.__name__),
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Volumes/Cased/Projects/cloud-functions/functions/.venv/lib/python3.11/site-packages/firebase_functions/options.py", line 1120, in _endpoint
assert len(
^^^^
AssertionError: HttpsOptions: Invalid option for invoker - must be a non-empty list.
Hello @thanhbinh01234. The invoker
argument expects a string. From your comment, you are passing True
. Could you check or provide a code sample with this fix?
I made a mistake in the original comment. I already passed invoker="public"
as shown in the exception stack.
Could you provide me with a simple code sample which correctly reproduces this issue? Also, please provide me with your Python version as well as the SDK version you're using. If you are using an older version, do check if this still occurs on the latest version as well. Thank you
@exaby73 The problem seems to be an off-by-one error.
https://github.com/firebase/firebase-functions-python/blob/db1eb6cfc21ac3c403d9804b638a374c6590ff1b/src/firebase_functions/options.py#L1135-L1137
This asserts the list length must have at least two items. invoker="public"
gets coerced to invoker=["public"]
which fails the assertion, but invoker=["user1", "user2"]
passes.