langflow icon indicating copy to clipboard operation
langflow copied to clipboard

Langflow not loading all required Environment variable mentioned in LANGFLOW_VARIABLES_TO_GET_FROM_ENVIRONMENT

Open codenprogressive opened this issue 1 year ago • 5 comments

Describe the bug Trying to load 3 global variables from Environment. only the first variable is loaded and not the second

Browser and Version

  • Browser: Edge
  • Version: 126.0.2592.81

To Reproduce Steps to reproduce the behavior:

  1. my .env file: includes the lines:

LANGFLOW_STORE_ENVIRONMENT_VARIABLES = true
LANGFLOW_VARIABLES_TO_GET_FROM_ENVIRONMENT='["default_gcp_project", "default_gcp_location", "default_gcp_dataset"]'
  1. launch Langflow: python -m langflow run --components-path /src_backend_platform/ --env-file /env/.env
  2. Only the first variable is loaded in Langflow: default_gcp_project

Screenshots

image

codenprogressive avatar Jul 04 '24 01:07 codenprogressive

@liwalayouni Hello! I'm here to help you with any issues you encounter. I can assist with bug fixes, answer questions, and guide you on becoming a contributor. While waiting for a human maintainer, feel free to ask me anything.

Ensure that your .env file includes the following line without spaces around the = sign:

LANGFLOW_STORE_ENVIRONMENT_VARIABLES=true

Additionally, make sure that LANGFLOW_VARIABLES_TO_GET_FROM_ENVIRONMENT is correctly formatted as a JSON-encoded string:

LANGFLOW_VARIABLES_TO_GET_FROM_ENVIRONMENT='["default_gcp_project", "default_gcp_location", "default_gcp_dataset"]'

If the issue persists, it might be related to a known bug in Langflow v1.0.6, where the code attempts to override environment variables using locals(), which may not work as intended in all cases [1].

To continue talking to Dosu, mention @dosu.

dosubot[bot] avatar Jul 04 '24 01:07 dosubot[bot]

@dosu, I made sure the .env is as the following:

LANGFLOW_STORE_ENVIRONMENT_VARIABLES=true
LANGFLOW_VARIABLES_TO_GET_FROM_ENVIRONMENT='["default_gcp_location", "default_gcp_dataset", "default_gcp_project"]'

this is still resulting into loading only the first variable.

codenprogressive avatar Jul 04 '24 01:07 codenprogressive

To ensure that all specified environment variables are loaded in Langflow, verify the following:

  1. Correct Formatting in .env File: Ensure there are no spaces around the = sign and the JSON string is correctly formatted:

    LANGFLOW_STORE_ENVIRONMENT_VARIABLES=true
    LANGFLOW_VARIABLES_TO_GET_FROM_ENVIRONMENT='["default_gcp_location", "default_gcp_dataset", "default_gcp_project"]'
    
  2. Environment Variables Defined: Make sure that the environment variables default_gcp_location, default_gcp_dataset, and default_gcp_project are defined in your environment.

  3. Langflow Version: Ensure you are using the latest version of Langflow, as there might be fixes for known issues in newer releases.

  4. Loading Mechanism: Langflow uses the load_dotenv function to load environment variables. If there are issues, they might be logged. Check the logs for any errors or warnings related to environment variable loading.

If the issue persists, it might be related to a known limitation in Langflow v1.0.6, where only the first variable is loaded due to how the environment variables are processed. This can be found in the src/backend/base/langflow/__main__.py file [1].

You can also try setting the environment variables directly in your shell before running Langflow:

export default_gcp_location="your_value"
export default_gcp_dataset="your_value"
export default_gcp_project="your_value"
python -m langflow run --components-path /src_backend_platform/ --env-file /env/.env

This approach ensures that the variables are available in the environment when Langflow starts.

To continue talking to Dosu, mention @dosu.

dosubot[bot] avatar Jul 04 '24 01:07 dosubot[bot]

Unfortunately still not working! looks like it is a bug. Anyone else can confirm able to load multiple environment variable?

codenprogressive avatar Jul 04 '24 13:07 codenprogressive

I just posted a bug #2717 a few hours ago which may relate to your issue.

peteBarahon avatar Jul 16 '24 08:07 peteBarahon

Hi, @codenprogressive . How are you?

The issue has been fixed in PR #2971. I tested it and was able to load the environment variables you mentioned, as shown in the image:

20240729070019_624x637

If you encounter any other issues, please open a new issue!

Thank you very much for your collaboration!

italojohnny avatar Jul 29 '24 10:07 italojohnny