Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[🐛 BUG] Unable to load configurations from an env file #2453

Open
1 of 7 tasks
chongli6319 opened this issue Feb 18, 2025 · 0 comments
Open
1 of 7 tasks

[🐛 BUG] Unable to load configurations from an env file #2453

chongli6319 opened this issue Feb 18, 2025 · 0 comments
Labels
⚙️Configuration Related to Taipy Configuration 📄 Documentation Internal or public documentation 🖰 GUI Related to GUI 💥Malfunction Addresses an identified problem. 🟧 Priority: High Must be addressed as soon

Comments

@chongli6319
Copy link

chongli6319 commented Feb 18, 2025

What went wrong? 🤔

Hi,

So we prefer to keep all our configurations in a env file rather than parameters in the main file, so we found the following from the doc.

Configuring with a .env file

All parameters can also be set to any values and stored as a list of key-value pairs in a text file for your Gui instance to consume. The name of this file is the one provided as the env_filename parameter to the Gui constructor.

If you have such a configuration file, then the value associated with a configuration parameter will override the one provided in the run() method of your Gui instance.

It sounds like if we provide an env file and specify it with the env_filename parameter it should override anything provided in the run() function. However, for some reason, it didn't work.

Expected Behavior

As an example, I created a simple .env file and it only contains one line:
run_browser=False
and I specified the env_filename by doing the following:
Gui(env_filename=".env").run()

I expected taipy to NOT open a browser

Steps to Reproduce Issue

1.create a .env file and put line run_browser=False
2.specify env_filename in your Gui constructor in the main.py file like Gui(env_filename=".env").run()
3.execute taipy run main.py

Solution Proposed

I don't have a solution yet but I spent some time digging the code and here's what I found:

  • the function that is used to handle this env_filename parameter resides in the gui/config.py file, function signature def _build_config(self, root_dir, env_filename, kwargs)
  • the actual logic is in the block if os.path.isfile(env_file_abs_path):
  • maybe I misunderstood but it seems this line should overwrite the value config[key] = value if config[key] is None else type(config[key])(value) # type: ignore
  • however, the config already has a default value, for example, run_browser=True by default
  • if it can NOT override existing configs (because they may have default values), how does it work? Or did I misunderstand the doc?
    Thank you.

[PS]
just want to mention that normally boolean type environment variables are not supported so I also tried something like run_browser=0 but still no luck

Screenshots

Image

Additional Context

Acceptance Criteria

  • A unit test reproducing the bug is added.
  • Any new code is covered by a unit tested.
  • Check code coverage is at least 90%.
  • The bug reporter validated the fix.
  • Related issue(s) in taipy-doc are created for documentation and Release Notes are updated.

Code of Conduct

  • I have checked the existing issues.
  • I am willing to work on this issue (optional)
@chongli6319 chongli6319 added the 💥Malfunction Addresses an identified problem. label Feb 18, 2025
@jrobinAV jrobinAV added 📄 Documentation Internal or public documentation ⚙️Configuration Related to Taipy Configuration 🖰 GUI Related to GUI 🟧 Priority: High Must be addressed as soon labels Feb 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
⚙️Configuration Related to Taipy Configuration 📄 Documentation Internal or public documentation 🖰 GUI Related to GUI 💥Malfunction Addresses an identified problem. 🟧 Priority: High Must be addressed as soon
Projects
None yet
Development

No branches or pull requests

2 participants