Skip to content

FloatParam is not parsing env var properly #209

Closed
@vpusher

Description

@vpusher

I have been working with Python Cloud Functions for Firebase for a few weeks now and we are having an issue when it comes to float params with FloatParam.

Basic code to reproduce:

# .env
MY_FLOAT=0.0
# main.py
from firebase_functions.params import FloatParam
import firebase_admin

firebase_admin.initialize_app()

my_float = FloatParam("MY_FLOAT").value

From that setup, I have 2 issues:

  1. The first one is that params types (string, int, boolean, float ...) cannot be read outside of a function implementation (i.e functions annotated with @tasks_fn.on_task_dispatched or @https_fn.on_call for example)
  2. Second one is, whenever I move the reading part inside of Callable/Queue function implementation, my env var value got wrapped into an array (only for float params), then I got the following error when the CF tries to start up in Cloud Run:
File "/layers/google.python.pip/pip/lib/python3.12/site-packages/firebase_functions/params.py", line 353, in value
    return float(_os.environ[self.name])
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: could not convert string to float: '["0.0"]'

NB: That "array wrapping" behaviour for floats is not happening locally with emulators.

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions